<?php

namespace Dms\Controller;
use Dms\Controller\CommonController;

class ProductController extends CommonController
{

	/**
	 * [local_info description]当地游信息列表
	 * @return [type] [description]
	 */
	public function local_info()
	{

		$keyword  = I('get.keyword');
		$where 	  = array();
		if(eregi('^[0-9]+$',$str))
		{
			$where['orderID']    = array('like',"%$keyword%");
		}
		else
		{
			$where['customerName']    = array('like',"%$keyword%");
		}
		$list       = M2('local_input')->where($where)->order('id')->select();
		$this->list = $list;

		$this->menuID   = '60';
		$this->menuName = '当地游信息列表';
		$this->display();
	}


	/**
	 * [local_info_edit description]详情
	 * @return [type] [description]
	 */
	public function local_info_edit()
	{

		$id = I('get.id');
		if($id)
		{
			//基础信息
			$local_input = M2('local_input')->where(array('id'=>$id))->find();
			$this->local_input = $local_input;
			//接机、送机、转机
			$local_airplane = M2('local_airplane')->where(array('inputID'=>$local_input['id']))->select();
			foreach ($local_airplane as $key => $value)
			{
				$local_airplane[$key]['carName'] = M('local_cartype')->where(array('id'=>$value['carType']))->getField('carName');
			}
			$this->local_airplane = $local_airplane;
		}
		$this->menuID      = '60';
		$this->menuName    = '当地游信息修改';
		$this->display();
	}


	/**
	 * [local_info_add description]当地游添加
	 * @return [type] [description]
	 */
	public function local_info_add()
	{

		$this->menuID      = '60';
		$this->menuName    = '当地游信息添加';
		$this->display();
	}


	/**
	 * [local_info_exportlist description]导出当地游所有信息
	 * @return [type] [description]
	 */
	public function local_info_exportlist()
	{
		$startDate         = I('post.startDate',0);
		$endDate           = I('post.endDate',0);
		$where             = array();
		if($startDate != 0 && $endDate != 0)
		{
			$where['addTime'] = array('between',array(strtotime($startDate),strtotime($endDate)));
		}
		$list              = M2('local_input')->where($where)->order('id')->select();
		if($list)
		{

			$objPHPExcel = writeExcel();
			$objPHPExcel->setActiveSheetIndex(0);
			$objPHPExcel->getActiveSheet()->mergeCells('N1:S1');
			$objPHPExcel->getActiveSheet()->SetCellValue('N1', '当地游用户信息');
			$objPHPExcel->getActiveSheet()->getStyle('N1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

			$objPHPExcel->getActiveSheet()->SetCellValue('N2','订单号');
			$objPHPExcel->getActiveSheet()->SetCellValue('O2','姓名');
			$objPHPExcel->getActiveSheet()->SetCellValue('P2','国内手机号');
			$objPHPExcel->getActiveSheet()->SetCellValue('Q2','国外手机号');
			$objPHPExcel->getActiveSheet()->SetCellValue('R2','邮箱地址');
			$objPHPExcel->getActiveSheet()->SetCellValue('S2','是否落地签');

			//酒店信息
			$objPHPExcel->getActiveSheet()->SetCellValue('M1', '酒店信息');
			$objPHPExcel->getActiveSheet()->SetCellValue('M2', '名称');
			$i = '3';
			foreach ($list as $key => $value)
			{
				$objPHPExcel->getActiveSheet()->SetCellValue('N'.$i, $value['orderID']);
				$objPHPExcel->getActiveSheet()->SetCellValue('O'.$i, $value['customerName']);
				$objPHPExcel->getActiveSheet()->SetCellValue('P'.$i, $value['customerMobile']);
				$objPHPExcel->getActiveSheet()->SetCellValue('Q'.$i, $value['customerMobileHome']);
				$objPHPExcel->getActiveSheet()->SetCellValue('R'.$i, $value['customerEmail']);
				$objPHPExcel->getActiveSheet()->SetCellValue('M'.$i, $value['hotelName']);

				if($value['isLandingSign']=='1')
				{
					$isLandingSign = '是';
				}
				else
				{
					$isLandingSign = '否';
				}
				$objPHPExcel->getActiveSheet()->SetCellValue('S'.$i, $isLandingSign);
				//接机信息
				$jieji_list = M2('local_airplane')->where(array('inputID'=>$value['id'],'airplaneType'=>'1'))->select();
				$objPHPExcel->getActiveSheet()->mergeCells('A1:D1');
				$objPHPExcel->getActiveSheet()->SetCellValue('A1', '接机信息');
				$objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$objPHPExcel->getActiveSheet()->SetCellValue('A2','航班号');
				$objPHPExcel->getActiveSheet()->SetCellValue('B2','到达日期');
				$objPHPExcel->getActiveSheet()->SetCellValue('C2','成人数量');
				$objPHPExcel->getActiveSheet()->SetCellValue('D2','儿童数量');
				foreach ($jieji_list as $k_jj => $v_jj)
				{
					$time = date('Y-m-d',$v_jj['arrivalDate']);
					$objPHPExcel->getActiveSheet()->SetCellValue('A'.$i, $v_jj['flightNumber']);
					$objPHPExcel->getActiveSheet()->SetCellValue('B'.$i, $time);
					$objPHPExcel->getActiveSheet()->SetCellValue('C'.$i, $v_jj['adultNum']);
					$objPHPExcel->getActiveSheet()->SetCellValue('D'.$i, $v_jj['childNum']);
				}

				//送机信息
				$songji_list = M2('local_airplane')->where(array('inputID'=>$value['id'],'airplaneType'=>'2'))->select();
				$objPHPExcel->getActiveSheet()->mergeCells('E1:H1');
				$objPHPExcel->getActiveSheet()->SetCellValue('E1', '送机信息');
				$objPHPExcel->getActiveSheet()->getStyle('E1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

				$objPHPExcel->getActiveSheet()->SetCellValue('E2','航班号');
				$objPHPExcel->getActiveSheet()->SetCellValue('F2','到达日期');
				$objPHPExcel->getActiveSheet()->SetCellValue('G2','成人数量');
				$objPHPExcel->getActiveSheet()->SetCellValue('H2','儿童数量');

				foreach ($songji_list as $k_sj => $v_sj)
				{
					$time = date('Y-m-d',$v_sj['arrivalDate']);
					$objPHPExcel->getActiveSheet()->SetCellValue('E'.$i, $v_sj['flightNumber']);
					$objPHPExcel->getActiveSheet()->SetCellValue('F'.$i, $time);
					$objPHPExcel->getActiveSheet()->SetCellValue('G'.$i, $v_sj['adultNum']);
					$objPHPExcel->getActiveSheet()->SetCellValue('H'.$i, $v_sj['childNum']);
				}

				//转机信息
				$zhuanji_list = M2('local_airplane')->where(array('inputID'=>$value['id'],'airplaneType'=>'3'))->select();
				$objPHPExcel->getActiveSheet()->mergeCells('I1:L1');
				$objPHPExcel->getActiveSheet()->SetCellValue('I1', '送机信息');
				$objPHPExcel->getActiveSheet()->getStyle('I1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

				$objPHPExcel->getActiveSheet()->SetCellValue('I2','航班号');
				$objPHPExcel->getActiveSheet()->SetCellValue('J2','到达日期');
				$objPHPExcel->getActiveSheet()->SetCellValue('K2','成人数量');
				$objPHPExcel->getActiveSheet()->SetCellValue('L2','儿童数量');

				//设置颜色
				if($key%2 == 0)
				{
					$color = '#F0FFFF';
				}
				else
				{
					$color = '#FFFFE0';
				}
				foreach ($zhuanji_list as $k_zj => $v_zj)
				{
					if($k_zj != '0')$i++;
					$time = date('Y-m-d',$v_zj['arrivalDate']);
					$objPHPExcel->getActiveSheet()->SetCellValue('I'.$i, $v_zj['flightNumber']);
					$objPHPExcel->getActiveSheet()->SetCellValue('J'.$i, $time);
					$objPHPExcel->getActiveSheet()->SetCellValue('K'.$i, $v_zj['adultNum']);
					$objPHPExcel->getActiveSheet()->SetCellValue('L'.$i, $v_zj['childNum']);
					//设置颜色
					$objPHPExcel->getActiveSheet()->getStyle('A'.$i.':S'.$i)->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
					$objPHPExcel->getActiveSheet()->getStyle('A'.$i.':S'.$i)->getFill()->getStartColor()->setARGB($color);

					//设置边框
					$objPHPExcel->getActiveSheet()->getStyle('A'.$i.':S'.$i)->getBorders()->getAllBorders()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN);

				}

				//设置颜色
				$objPHPExcel->getActiveSheet()->getStyle('A'.$i.':S'.$i)->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
				$objPHPExcel->getActiveSheet()->getStyle('A'.$i.':S'.$i)->getFill()->getStartColor()->setARGB($color);
				//设置边框
				$objPHPExcel->getActiveSheet()->getStyle('A'.$i.':S'.$i)->getBorders()->getAllBorders()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN);
				$i++;
				//宽度
				$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(15);
				$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(15);
				$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(15);
		        $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(15);
		        $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(15);
		        $objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(15);
		        $objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth(15);
		        $objPHPExcel->getActiveSheet()->getColumnDimension('N')->setWidth(30);
		        $objPHPExcel->getActiveSheet()->getColumnDimension('O')->setWidth(15);
		        $objPHPExcel->getActiveSheet()->getColumnDimension('P')->setWidth(15);
		        $objPHPExcel->getActiveSheet()->getColumnDimension('Q')->setWidth(15);
		        $objPHPExcel->getActiveSheet()->getColumnDimension('R')->setWidth(20);


			}
			exportExcel($objPHPExcel,'当地游用户信息表');
			exit;
		}
		else
		{
			$this->error('暂时没有所选时间段数据');
		}

	}

	/**
	 * [FunctionName description]导出当地游修改数据
	 * @param string $value [description]
	 */
	public function local_info_exportedit()
	{
		$startDate         = I('post.startDate',0);
		$endDate           = I('post.endDate',0);
		$where             = array();
		if($startDate != 0 && $endDate != 0)
		{

			$where['editTime'] = array('between',array(strtotime($startDate),strtotime($endDate)));
		}
		else
		{
			$where['editTime'] = array('neq','0');
		}

		$list              = M2('local_input')->where($where)->order('id')->select();
		// echo M2('local_input')->getlastsql();exit;
		if($list)
		{

			$objPHPExcel = writeExcel();
			$objPHPExcel->setActiveSheetIndex(0);
			$objPHPExcel->getActiveSheet()->mergeCells('N1:S1');
			$objPHPExcel->getActiveSheet()->SetCellValue('N1', '当地游用户信息');
			$objPHPExcel->getActiveSheet()->getStyle('N1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->SetCellValue('N2','订单号');
			$objPHPExcel->getActiveSheet()->SetCellValue('O2','姓名');
			$objPHPExcel->getActiveSheet()->SetCellValue('P2','国内手机号');
			$objPHPExcel->getActiveSheet()->SetCellValue('Q2','国外手机号');
			$objPHPExcel->getActiveSheet()->SetCellValue('R2','邮箱地址');
			$objPHPExcel->getActiveSheet()->SetCellValue('S2','是否落地签');

			//酒店信息
			$objPHPExcel->getActiveSheet()->SetCellValue('M1', '酒店信息');
			$objPHPExcel->getActiveSheet()->SetCellValue('M2', '名称');

			$i = '3';
			foreach ($list as $key => $value)
			{
				$objPHPExcel->getActiveSheet()->SetCellValue('N'.$i, $value['orderID']);
				$objPHPExcel->getActiveSheet()->SetCellValue('O'.$i, $value['customerName']);
				$objPHPExcel->getActiveSheet()->SetCellValue('P'.$i, $value['customerMobile']);
				$objPHPExcel->getActiveSheet()->SetCellValue('Q'.$i, $value['customerMobileHome']);
				$objPHPExcel->getActiveSheet()->SetCellValue('R'.$i, $value['customerEmail']);
				$objPHPExcel->getActiveSheet()->SetCellValue('M'.$i, $value['hotelName']);

				if($value['isLandingSign']=='1')
				{
					$isLandingSign = '是';
				}
				else
				{
					$isLandingSign = '否';
				}
				$objPHPExcel->getActiveSheet()->SetCellValue('S'.$i, $isLandingSign);
				//接机信息
				$jieji_list = M2('local_airplane')->where(array('inputID'=>$value['id'],'airplaneType'=>'1'))->select();
				$objPHPExcel->getActiveSheet()->mergeCells('A1:D1');
				$objPHPExcel->getActiveSheet()->SetCellValue('A1', '接机信息');
				$objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$objPHPExcel->getActiveSheet()->SetCellValue('A2','航班号');
				$objPHPExcel->getActiveSheet()->SetCellValue('B2','到达日期');
				$objPHPExcel->getActiveSheet()->SetCellValue('C2','成人数量');
				$objPHPExcel->getActiveSheet()->SetCellValue('D2','儿童数量');
				foreach ($jieji_list as $k_jj => $v_jj)
				{
					$time = date('Y-m-d',$v_jj['arrivalDate']);
					$objPHPExcel->getActiveSheet()->SetCellValue('A'.$i, $v_jj['flightNumber']);
					$objPHPExcel->getActiveSheet()->SetCellValue('B'.$i, $time);
					$objPHPExcel->getActiveSheet()->SetCellValue('C'.$i, $v_jj['adultNum']);
					$objPHPExcel->getActiveSheet()->SetCellValue('D'.$i, $v_jj['childNum']);
				}

				//送机信息
				$songji_list = M2('local_airplane')->where(array('inputID'=>$value['id'],'airplaneType'=>'2'))->select();
				$objPHPExcel->getActiveSheet()->mergeCells('E1:H1');
				$objPHPExcel->getActiveSheet()->SetCellValue('E1', '送机信息');
				$objPHPExcel->getActiveSheet()->getStyle('E1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$objPHPExcel->getActiveSheet()->SetCellValue('E2','航班号');
				$objPHPExcel->getActiveSheet()->SetCellValue('F2','到达日期');
				$objPHPExcel->getActiveSheet()->SetCellValue('G2','成人数量');
				$objPHPExcel->getActiveSheet()->SetCellValue('H2','儿童数量');

				foreach ($songji_list as $k_sj => $v_sj)
				{
					$time = date('Y-m-d',$v_sj['arrivalDate']);
					$objPHPExcel->getActiveSheet()->SetCellValue('E'.$i, $v_sj['flightNumber']);
					$objPHPExcel->getActiveSheet()->SetCellValue('F'.$i, $time);
					$objPHPExcel->getActiveSheet()->SetCellValue('G'.$i, $v_sj['adultNum']);
					$objPHPExcel->getActiveSheet()->SetCellValue('H'.$i, $v_sj['childNum']);
				}

				//转机信息
				$zhuanji_list = M2('local_airplane')->where(array('inputID'=>$value['id'],'airplaneType'=>'3'))->select();
				$objPHPExcel->getActiveSheet()->mergeCells('I1:L1');
				$objPHPExcel->getActiveSheet()->SetCellValue('I1', '送机信息');
				$objPHPExcel->getActiveSheet()->getStyle('I1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$objPHPExcel->getActiveSheet()->SetCellValue('I2','航班号');
				$objPHPExcel->getActiveSheet()->SetCellValue('J2','到达日期');
				$objPHPExcel->getActiveSheet()->SetCellValue('K2','成人数量');
				$objPHPExcel->getActiveSheet()->SetCellValue('L2','儿童数量');

				//设置颜色
				if($key%2 == 0)
				{
					$color = '#F0FFFF';
				}
				else
				{
					$color = '#FFFFE0';
				}
				foreach ($zhuanji_list as $k_zj => $v_zj)
				{
					if($k_zj != '0')$i++;
					$time = date('Y-m-d',$v_zj['arrivalDate']);
					$objPHPExcel->getActiveSheet()->SetCellValue('I'.$i, $v_zj['flightNumber']);
					$objPHPExcel->getActiveSheet()->SetCellValue('J'.$i, $time);
					$objPHPExcel->getActiveSheet()->SetCellValue('K'.$i, $v_zj['adultNum']);
					$objPHPExcel->getActiveSheet()->SetCellValue('L'.$i, $v_zj['childNum']);
					//设置颜色
					$objPHPExcel->getActiveSheet()->getStyle('A'.$i.':S'.$i)->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
					$objPHPExcel->getActiveSheet()->getStyle('A'.$i.':S'.$i)->getFill()->getStartColor()->setARGB($color);

					//设置边框
					$objPHPExcel->getActiveSheet()->getStyle('A'.$i.':S'.$i)->getBorders()->getAllBorders()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN);

				}
				//设置颜色
				$objPHPExcel->getActiveSheet()->getStyle('A'.$i.':S'.$i)->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
				$objPHPExcel->getActiveSheet()->getStyle('A'.$i.':S'.$i)->getFill()->getStartColor()->setARGB($color);
				//设置边框
				$objPHPExcel->getActiveSheet()->getStyle('A'.$i.':S'.$i)->getBorders()->getAllBorders()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN);
				$i++;
				//宽度
				$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(15);
				$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(15);
				$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(15);
		        $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(15);
		        $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(15);
		        $objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(15);
		        $objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth(15);
		        $objPHPExcel->getActiveSheet()->getColumnDimension('N')->setWidth(30);
		        $objPHPExcel->getActiveSheet()->getColumnDimension('O')->setWidth(15);
		        $objPHPExcel->getActiveSheet()->getColumnDimension('P')->setWidth(15);
		        $objPHPExcel->getActiveSheet()->getColumnDimension('Q')->setWidth(15);
		        $objPHPExcel->getActiveSheet()->getColumnDimension('R')->setWidth(20);


			}
			exportExcel($objPHPExcel,'当地游用户信息表');
			exit;
		}
		else
		{
			$this->error('暂时没有所选时间段数据');
		}

	}

	/**
	 * [supplier_ajax description]
	 * @return [type] [description]
	 */
	/*public function supplier_ajax()
	{

        $key = I('post.supplierkey');
        $supplier=M('supplier')->where(" name like '%{$key}%' ")->select();
        if(empty($supplier)==false)
        {
            $data="<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
            foreach ($supplier as $key=>$value)
            {
                $data .= "<tr>
                <td align='left'>
                <script>
                var rds=form_do.supplier;for(var i=0;i<rds.length;i++)
                 {

                    if(i==0)
                       {
                           rds[i].checked=true;

                      }
                  }
                 </script>
                    <input type='radio' checked  name='supplier' value='".$value['id']."' ></td>
                <td align='left'>".$value['name']."</td>

              </tr>";
            }
            $data.="   </table> ";
        }
        else
        {
               $supplierall=M('supplier')->select();
               $data="<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
                foreach ($supplierall as $key2=>$value2)
                {
                    $data .= "<tr>
                    <td align='left'>
                    <script>
                    var rds=form_do.supplier;for(var i=0;i<rds.length;i++)
                     {

                        if(i==0)
                           {
                               rds[i].checked=true;

                          }
                      }
                     </script>
                        <input type='radio' checked  name='supplier' value='".$value2['id']."' ></td>
                    <td align='left'>".$value2['name']."</td>

                  </tr>";
                }
                $data.="   </table> ";
        }
        $this->ajaxReturn($data);

	}*/

	/*public function importKD()
	{

	    if(IS_POST)
	    {
	        $upload = Upload();
	        $info = $upload['msg']['KD'];
	        $filename = __ROOT__."Upload/".$info['savepath'].$info['savename'];
	        $data = readExcel($filename);

	        if($data == false)
	        {
	            $this->error('文件格式错误');
	        }

	        $departure= M2('departure')->where(array('name' => $data[9][1]))->getField('id');
	        if(empty($departure)==false)
	        {
	            $departureid	= $departure;
	        }
	        else
	        {
	             $departureid= 0;
	        }



	        $city= M2('destination')->where(array('name'=>$data[10][1],'deep'=>3))->find();
	        if(empty($city)==false)
	        {
	            $cityid	= $city['id'];
	            $country= M2('destination')->where(array('id'=>$city['pid'],'deep'=>2))->find();
	            $countryid=$country['id'];
	            $continent= M2('destination')->where(array('id'=>$country['pid'],'deep'=>1))->find();
	            $continentid=$continent['id'];

	        }
	        else
	        {
	            $continentid=0;
	            $countryid=0;
	            $cityid	= 0;
	        }

	        $data1 =array(
				'title'              => $data[4][1],
				'arrival_one'        => $continentid,
				'arrival_two'        => $countryid,
				'arrival_three'      => $cityid,
				'departure_province' => $departureid,

				'travel_days'        => $data[11][1],
				'travel_night'       =>  $data[11][3],

				'dateline'           => time(),
				'updatetime'         => time(),
				'click'              => rand(10,95),
				'adduser'            => getIdenty(),
				'status'             => 0,

	        );
	       $id = M3('product')->add($data1);

	        for ($i=5;$i<=8;$i++)
	        {
	            $data2 =array(
	                'productID'     => $id,
	                'content'     	=> $data[$i][1],
	             );
	            M3('product_highlight')->add($data2);

	        }

	        $data3 =array(
				'productID'         => $id,
				'costInclude'       => $data[25][1],
				'reservationNotice' => $data[34][1],
	        );
	        M3('product_detail')->add($data3);

	        $data4 =array(
	            'pid'     => $id,
	            'name'     	=> '航线1',
	        );
	        $airplane_flight=M3('airplane_flight')->add($data4);


	        for ($i=13;$i<=14;$i++)
	        {
    	            $data5 =array(

						'extend'           =>  $data[$i][1],
						'pid'              => $id,
						'flight_date'      =>$airplane_flight ,
						'departure'        =>  $data[$i][2],
						'departure_time'   =>$data[$i][3],
						'destination'      => $data[$i][4],
						'destination_time' =>$data[$i][5],
						'flight_number'    =>$data[$i][7],

    	            );

    	            M3('airplane')->add($data5);

	        }



	       if(empty($id)==false)
	        {
	            $this->success("导入数据成功！");
	        }
	        else
	        {
	            $this->error("导入数据失败！");
	        }

	        exit;
	    }

	}*/


    /**
     * [sell description]
     * @return [type] [description]
     */
    public function sell()
    {

		$where = array();
		$keyword = I('get.keyword');
		$status  = I('get.status','全部');
		$type    = I('get.type','全部');

		$keyword = trimall($keyword);

		$where['status'] = array('neq','-1');
        if(!empty($keyword))
		{
			$where['_string'] = "(`id` = '".$keyword."' ) OR (`title` LIKE '%".$keyword."%') OR (`libraryProductID` = '".$keyword."')";
		}
		if($status != '全部')$where['status'] = $status;

		$this->status = $status;

		switch ($type)
		{
			case '1':
				$where['type'] = '1';
				break;
			case '2':
				$where['type'] = '2';
				break;
			case '3':
				$where['special'] = '1';
				break;
		}
		$this->type   = $type;
		$where['type'] = array('neq',4);
        /*$count = M2('pack_product_travel')->where($where)->count();
		$PageClass  = new \Think\Page($count,10);
		$page  = $PageClass->show();*/

		$product = M2('pack_product_travel')->where($where)->order(array('status'=>'DESC','id'=>'DESC'))->select();
		// $product = M2('pack_product_travel')->where($where)->limit($PageClass->firstRow.','.$PageClass->listRows)->order(array('status'=>'DESC','id'=>'DESC'))->select();
		// echo M2('pack_product_travel')->getLastSql();
		foreach($product as $key => $value)
		{
			$categoryParentName = M2('pack_product_category')->where(array('id'=>$value['categoryParentID']))->getField('categoryName');
			$categoryChildName  = M2('pack_product_category')->where(array('id'=>$value['categoryChildID']))->getField('categoryName');
			$product[$key]['categoryName'] = $categoryParentName.'/'.$categoryChildName;

			$bigPic = M2('destination_detail')->where(array('pid'=>'5','destination'=>$value['cityID']))->getField('bigPic');

			if(empty($value['litPic']) == true && empty($bigPic) == false)
			{
				$product[$key]['litPic'] = 'http://www.tripvip.cn'.$bigPic;
			}

			$product[$key]['litPic'] = imgUrlComplete($value['litPic']);
			$product[$key]['bigPic'] = imgUrlComplete($value['bigPic']);

		}

		$this->keyword  = $keyword;
		// $this->page     = $page;
		$this->list    	= $product;
		$this->menuID   = '76';
		$this->menuName = '直销产品';

    	$this->display();
    }

    /**
     * [selladd description]
     * @return [type] [description]
     */
    public function selladd()
    {
    	if(IS_POST)
		{
			$data['title']              = I('post.title');
			$data['type']               = I('post.type',1);
			$data['categoryInterestID'] = implode('|', I('post.catID',array()));
			$data['verify']             = I('post.verify');
			$data['special']            = I('post.special');
			$data['extend']             = I('post.extend');
			$data['departureCityID']    = implode('|',I('post.departureCityID',array()));
			$data['areaID']             = implode('|',I('post.areaID',array()));
			$data['countryID']          = implode('|',I('post.countryID',array()));
			$data['cityID']             = implode('|',I('post.cityID',array()));
			$data['departureDate']      = I('post.departureDate');
			$data['travelDays']         = I('post.travelDays');
			$data['travelNight']        = I('post.travelNight');
			$data['marketPrice']        = I('post.marketPrice');
			$data['price']              = I('post.price');
			$data['litPic']             = I('post.litPic');
			$originalImages             = I('post.bigPic');
			if(empty($originalImages) == false)
			{
				$data['bigPic']             = $originalImages;
			    $data['mobileBigPic'] 		= originalImagesMobile($originalImages);
			}
			$data['keyWords']           = I('post.keyWords');
			$data['type']               = '1';
			$data['dateLine']           = time();
			$data['adduserID']          = getIdenty();

			$productID = M3('pack_product_travel')->add($data);
			if($productID !== false)
			{
				$categoryParentID = I('post.categoryID');
				$categoryChildID  = I('post.packCategoryTwo');
				$categoryLabelID  = I('post.categorylabel',array());

				$labelCount = count($categoryLabelID);

				for ($i = 0; $i < $labelCount; $i++)
				{
					$labelData['productID']        = $productID;
					$labelData['categoryParentID'] = $categoryParentID;
					$labelData['categoryChildID']  = $categoryChildID;
					$labelData['categoryLabelID']  = $categoryLabelID[$i];
					M3('pack_product_label')->add($labelData);
				}

				//产品亮点
				for ($i=0; $i < 4; $i++)
				{
					$highlightData['productID'] = $productID;
					$highlightData['sort'] = $i+1;
					M3('pack_product_highlight')->add($highlightData);
				}

				//费用说明
				//预订须知
				//温馨提示
				$detailData['productID'] = $productID;
				M3('pack_product_detail')->add($detailData);

				$this->success('添加产品成功！',U(MODULE_NAME. '/Product/sell'));
			}
			else
			{
				$this->error('添加产品失败！');
			}
			exit;

		}

		//所属兴趣分类
		$catArr       = M2('label_class')->where(array('pid'=>'1'))->order('id ASC')->select();
		$this->catArr = $catArr;

		//主站分类
		//分类标签
		$categoryArr       = M2('pack_product_classlabel')->where(array('pId'=>'0'))->select();
		$this->categoryArr = $categoryArr;

		//出发地
		$this->departureHtml = departureHtml('','departureCityID[]');

		//目的地
		$destinationHtml                  = array();
		$destinationHtml['areaSelect']    = destinationHtml('', 'areaID[]', '1', 'destinationSelect(this)');
		$destinationHtml['countrySelect'] = destinationHtml('', 'countryID[]', '2', 'destinationSelect(this)');
		$destinationHtml['citySelect']    = destinationHtml('', 'cityID[]', '3');
		$this->destinationHtml            = $destinationHtml;

		$this->menuID   = '76';
		$this->menuName = '自由行产品添加';
		$this->display();
    }


    /**
     * [selledit description]
     * @return [type] [description]
     */
	public function selledit()
	{
		$id         = I('get.id');
		$this->id   = $id;
		$step       = I('get.step',0);
		$this->step = $step;

		//产品基本信息
		$product = M2('pack_product_travel')->where(array('id'=>$id))->find();
		if(empty($product) == true)$this->redirect(MODULE_NAME.'/Product/sell');

		if(IS_POST)
		{
			switch ($step)
			{
				case '0':
					$data['title']              = I('post.title');
					$data['categoryInterestID'] = implode('|', I('post.catID',array()));
					$data['verify']             = I('post.verify',1);
					$data['special']            = I('post.special');
					$data['extend']             = I('post.extend');
					$data['departureCityID']    = implode('|', I('post.departureCityID',array()));
					$data['areaID']             = implode('|', I('post.areaID',array()));
					$data['countryID']          = implode('|', I('post.countryID',array()));
					$data['cityID']             = implode('|', I('post.cityID',array()));
					$data['departureDate']      = I('post.departureDate');
					$data['travelDays']         = I('post.travelDays');
					$data['travelNight']        = I('post.travelNight');
					$data['marketPrice']        = I('post.marketPrice');
					$data['price']              = I('post.price');
					$data['litPic']             = I('post.litPic');
					$originalImages             = I('post.bigPic');
					if(empty($originalImages) == false)
					{
						$data['bigPic']             = $originalImages;
					    $data['mobileBigPic'] 		= originalImagesMobile($originalImages);
					}
					$data['keyWords']            = I('post.keyWords');
					$mobilebigPic                = I('post.mobilebigPic');
					// $data['libraryID']        = I('post.libraryID');
					// $data['libraryProductID'] = I('post.libraryProductID');
					$data['gainType']            = I('post.gainType');
					$data['gainNums']            = I('post.gainNums');
					$data['saleNums']            = I('post.saleNums',0);
					$data['sign']                = I('post.sign',0);

					if($mobilebigPic != false)$data['mobileBigPic'] = $mobilebigPic;
					/*if(imgUrlComplete($product['litPic']) != $data['litPic'])
					{
						delImg($product['litPic']);
					}
					if(imgUrlComplete($product['bigPic']) != $data['bigPic'])
					{
						delImg($product['bigPic']);
					}
					if(imgUrlComplete($product['mobileBigPic']) != $data['mobileBigPic'])
					{
						delImg($product['mobileBigPic']);
					}*/
					$result = M3('pack_product_travel')->where(array('id'=>$id))->save($data);

					$categoryParentID = I('post.categoryID');
					$categoryChildID  = I('post.packCategoryTwo');
					$categorylabelArr = I('post.categorylabel',array());

					$labelArr         = M2('pack_product_label')->where(array('productID'=>$id))->select();
					$labelCount       = count($categorylabelArr);
					$existsLabelCount = count($labelArr);
					if($labelCount == $existsLabelCount)
					{
						foreach ($labelArr as $key => $value)
						{
							$labelData['categoryParentID'] = $categoryParentID;
							$labelData['categoryChildID']  = $categoryChildID;
							$labelData['categoryLabelID']  = $categorylabelArr[$key];
							M3('pack_product_label')->where(array('id'=>$value['id']))->save($labelData);
						}
					}
					else if($labelCount > $existsLabelCount)
					{
						foreach ($labelArr as $key => $value)
						{
							$labelData['categoryParentID'] = $categoryParentID;
							$labelData['categoryChildID']  = $categoryChildID;
							$labelData['categoryLabelID']  = $categorylabelArr[$key];
							M3('pack_product_label')->where(array('id'=>$value['id']))->save($labelData);
						}

						for ($i=0; $i < ($labelCount - $existsLabelCount); $i++)
						{
							$labelData['productID']        = $id;
							$labelData['categoryParentID'] = $categoryParentID;
							$labelData['categoryChildID']  = $categoryChildID;
							$labelData['categoryLabelID']  = $categorylabelArr[$i+$existsLabelCount];

							M3('pack_product_label')->add($labelData);
						}
					}
					else if($labelCount < $existsLabelCount)
					{
						foreach ($labelArr as $key => $value)
						{
							if(($key+1) > $labelCount)
							{
								M3('pack_product_label')->where(array('id'=>$value['id']))->delete();
							}
							else
							{

								$labelData['categoryParentID'] = $categoryParentID;
								$labelData['categoryChildID']  = $categoryChildID;
								$labelData['categoryLabelID']  = $categorylabelArr[$key];
								M3('pack_product_label')->where(array('id'=>$value['id']))->save($labelData);
							}
						}
					}



					break;
				case '1':
					$content     = I('post.content',array());
					$reson       = I('post.reson',array());
					$highlightID = I('post.highlightID',array());
					if(empty($highlightID) == true)
					{
						$count = count($content);
						for ($i=0; $i < $count; $i++)
						{
							$data['productID'] = $id;
							$data['content']   = $content[$i];
							$data['reson']     = $reson[$i];
							$result = M3('pack_product_highlight')->add($data);
						}
					}
					else
					{

						$count = count($content);
						for ($i=0; $i < $count; $i++)
						{
							$data['content'] = $content[$i];
							$data['reson']   = $reson[$i];
							$result = M3('pack_product_highlight')->where(array('id'=>$highlightID[$i],'productID'=>$id))->save($data);
						}
					}
					break;
				case '2':
					$data['costInclude'] = I('post.costInclude', '', 'trim');
					$result = M3('pack_product_detail')->where(array('productID'=>$id))->save($data);
					break;
				case '3':
					$data['reservationNotice'] = I('post.reservationNotice','', 'trim');
					$result = M3('pack_product_detail')->where(array('productID'=>$id))->save($data);
					break;
				case '4':
					$data['warmReminder'] = I('post.warmReminder','', 'trim');
					$result = M3('pack_product_detail')->where(array('productID'=>$id))->save($data);
					break;
				case '5':
					$data['giftID'] = implode('|', I('post.giftID',array()));
					$result = M3('pack_product_travel')->where(array('id'=>$id))->save($data);
					break;
				case '6':
					$data['insuranceID'] = implode('|', I('post.insuranceID',array()));
					$result = M3('pack_product_travel')->where(array('id'=>$id))->save($data);
					break;
				case '7':
					$data['couponID'] = implode('|', I('post.coupon',array()));
					$result = M3('pack_product_travel')->where(array('id'=>$id))->save($data);
					break;

				case '9':
					$data['recommend']              = I('post.recommend');
					$data['headerImg']              = I('post.img');
					$data['reson']                  = I('post.reson');
					$data['recommendHotleReson']    = I('post.recommendHotleReson');
					$data['recommendAirplaneReson'] = I('post.recommendAirplaneReson');
					$find = M2('pack_recommend_reson')->where(array('productID'=>$id))->find();
					if($find == false)
					{
						$data['productID'] = $id;
						$result = M3('pack_recommend_reson')->add($data);
					}
					else
					{
						$result = M3('pack_recommend_reson')->where(array('productID'=>$id))->save($data);
					}
					break;

				default:
					# code...
					break;
			}

			if($result !== false)
			{
				$this->success('修改产品成功！');
			}
			else
			{
				$this->error('修改产品失败！');
			}
			exit;
		}

		//出发地
		$product['departureCityName'] = M2('departure')->where(array('id'=>$product['departureCityID']))->getField('name');
		//产品库标题
		$product['libraryTitle'] = M2('library')->where(array('id'=>$product['libraryID']))->getField('name');
		// var_dump($price);

		switch ($step)
		{
			case '1':
				//产品亮点
				$highlight = M2('pack_product_highlight')->where(array('productID'=>$product['id']))->order('sort')->select();
				$this->highlight = $highlight;
				break;
			case '2':
				//费用包含
				$costInclude = M2('pack_product_detail')->where(array('productID'=>$product['id']))->getField('costInclude');
				$this->costInclude = $costInclude;
				break;
			case '3':
				//预订须知
				$reservationNotice = M2('pack_product_detail')->where(array('productID'=>$product['id']))->getField('reservationNotice');
				$this->reservationNotice = $reservationNotice;
				break;
			case '4':
				//温馨提示
				$warmReminder = M2('pack_product_detail')->where(array('productID'=>$product['id']))->getField('warmReminder');
				$this->warmReminder = $warmReminder;
				break;
			case '5':
				//赠送信息
				$gifts = M2('gift')->field('id,title,litpic')->order('id DESC')->select();
				$giftIDArr   = explode('|', $product['giftID']);
				foreach($gifts as $key=>$value)
				{
					if(in_array($value['id'],$giftIDArr) == true)
					{
						$gifts[$key]['checked'] = 'checked';
					}

				}

				$this->gifts = $gifts;

				break;
			case '6':
				//附加保险
				$insurance = M2('insurance')->field('id,title,litpic,description')->order('sort,id')->select();
				$insuranceIDArr = explode('|', $product['insuranceID']);
				foreach($insurance as $key => $value)
				{

					if(in_array($value['id'],$insuranceIDArr))
					{
						$insurance[$key]['checked'] = 'checked';
					}
				}
				$this->insurance = $insurance;
				$this->productTypeName = '附加保险';
				break;
			case '7':

				//优惠券
				$coupontypeart = M2('coupons_mould')->field('*')->order('id')->select();
				$couponIDArr   = explode('|', $product['couponID']);
				foreach($coupontypeart as $key => $value)
				{
					$category = M2('coupons_category')->find($value['category_id']);
					$name = M2('coupons_cooperation')->find($value['cp_id']);
					$coupontypeart[$key]['category'] = $category['category_name'];
					$coupontypeart[$key]['name'] = $name['cooperative'];
					$coupontypeart[$key]['amount'] = $value['face_amount'];

					if(in_array($value['id'], $couponIDArr))
					{
						$coupontypeart[$key]['checked'] = ' checked="checked" ';
						$coupontypeart[$key]['picture_item2'] = ' picture_item2 ';
					}

				}
				$this->coupontypelist = $coupontypeart;
				break;
			case '8':
				//附加产品
				$addproduct       = M2('pack_addproduct')->where(array('productID'=>$product['id']))->select();
				foreach ($addproduct as $key => $value)
				{
					$addproduct[$key]['img'] = imgUrlComplete($value['img']);
				}
				$this->addproduct = $addproduct;
				$this->productTypeName = '附加产品';
				break;
			case '9':
				//棉签妹推荐
				$personRecommend = M2('pack_recommend_reson')->where(array('productID'=>$product['id']))->find();
				$personRecommend['headerImg'] = imgUrlComplete($personRecommend['headerImg']);
				$this->personRecommend = $personRecommend;
				break;
			case '10':
				//包含单品
				$contain = M2('pack_product_contain')->where(array('productID'=>$product['id']))->order('id ASC')->select();
				foreach ($contain as $key => $value)
				{
					$contain[$key]['img'] = imgUrlComplete($value['img']);
				}
				$this->contain = $contain;
				$this->productTypeName = '包含单品';
				break;
			case '11':
				//赠送单品
				$gifts = M2('pack_product_gifts')->where(array('productID'=>$product['id']))->select();
				foreach ($gifts as $key => $value)
				{
					$gifts[$key]['img'] = imgUrlComplete($value['img']);
				}
				$this->gifts = $gifts;
				$this->productTypeName = '赠送单品';
				break;
			default:
				//产品所选兴趣分类
				$catCheckArr = explode('|', $product['categoryInterestID']);
				//所属兴趣分类
				$catArr       = M2('label_class')->where(array('pid'=>'1'))->order('id')->select();
				foreach ($catArr as $key => $value)
				{
					if(in_array($value['id'],$catCheckArr) == true)
					{
						$catArr[$key]['checked'] = 'checked';
					}
				}
				$this->catArr = $catArr;

				//主站分类
				$classRow = M2('pack_product_label')->where(array('productID'=>$product['id']))->find();

				$categoryOneArr = M2('pack_product_classlabel')->where(array('pId'=>'0'))->select();
				$categoryHtmlOne = '';
				$categoryHtmlOne .= '<select name="categoryID" onchange="packCategory(this)">';
				$categoryHtmlOne .= '<option value="0">请选择</option>';
				foreach ($categoryOneArr as $key => $value)
				{
					if($value['id'] == $classRow['categoryParentID'])
					{
						$categoryHtmlOne .= '<option value="'.$value['id'].'" selected >'.$value['name'].'</option>';
					}
					else
					{
						$categoryHtmlOne .= '<option value="'.$value['id'].'" >'.$value['name'].'</option>';
					}
				}
				$categoryHtmlOne .= '</select>';
				$this->categoryHtmlOne = $categoryHtmlOne;

				$categoryTwoArr = M2('pack_product_classlabel')->where(array('pId'=>$classRow['categoryParentID']))->select();

				$categoryHtmlTwo = '';
				$categoryHtmlTwo .= '<select name="packCategoryTwo" onchange="categoryLabelList(this)">';
				$categoryHtmlTwo .= '<option value="0">请选择</option>';
				foreach ($categoryTwoArr as $key => $value)
				{
					if($value['id'] == $classRow['categoryChildID'])
					{
						$categoryHtmlTwo .= '<option value="'.$value['id'].'" selected >'.$value['name'].'</option>';
					}
					else
					{
						$categoryHtmlTwo .= '<option value="'.$value['id'].'" >'.$value['name'].'</option>';
					}
				}
				$categoryHtmlTwo .= '</select>';
				$this->categoryHtmlTwo = $categoryHtmlTwo;


				//主站分类标签
				$currLabelArr = M2('pack_product_label')->field('categoryLabelID')->where(array('productID'=>$product['id']))->select();
				$currLabel = array();
				foreach ($currLabelArr as $key => $value)
				{
					$currLabel[$key] = $value['categoryLabelID'];
				}

				if(empty($currLabel) == false)
				{
					$categorylabelArr = M2('pack_product_classlabel')->field('id,name')->where(array('pId'=>$classRow['categoryChildID']))->select();
					$categorylabelHtml = '';
					foreach ($categorylabelArr as $key => $value)
					{
						if(in_array($value['id'],$currLabel) == true)
						{
							$categorylabelHtml .= '<input type="checkbox" name="categorylabel[]" checked value="'.$value['id'].'" style="margin-left: 10px;">'.$value['name'];
						}
						else
						{
							$categorylabelHtml .= '<input type="checkbox" name="categorylabel[]" value="'.$value['id'].'" style="margin-left: 10px;">'.$value['name'];
						}
					}
					$this->categorylabelHtml = $categorylabelHtml;
				}

				//出发地
				$this->departureHtmlArr = departureHtml($product['departureCityID'],'departureCityID[]');
				$this->departureHtml = departureHtml('','departureCityID[]');
				//目的地
				$areaIDArr    = explode('|',$product['areaID']);
				$countryIDArr = explode('|',$product['countryID']);
				$cityIDArr    = explode('|',$product['cityID']);

				$destinationNums    = count($areaIDArr);
				$destinationArrHtml = array();
				for ($i=0; $i < $destinationNums; $i++)
				{
					$destinationArrHtml[$i]['areaSelect']    = destinationHtml($areaIDArr[$i], 'areaID[]', '1', 'destinationSelect(this)');
					$destinationArrHtml[$i]['countrySelect'] = destinationHtml($countryIDArr[$i],'countryID[]', '2', 'destinationSelect(this)');
					$destinationArrHtml[$i]['citySelect']    = destinationHtml($cityIDArr[$i],'cityID[]', '3');
				}
				$this->destinationArrHtml = $destinationArrHtml;

				$destinationHtml = array();
				$destinationHtml['areaSelect']    = destinationHtml('', 'areaID[]', '1', 'destinationSelect(this)');
				$destinationHtml['countrySelect'] = destinationHtml('', 'countryID[]', '2', 'destinationSelect(this)');
				$destinationHtml['citySelect']    = destinationHtml('', 'cityID[]', '3');
				$this->destinationHtml = $destinationHtml;
				$this->productTypeName = '产品';

				$product['litPic'] = imgUrlComplete($product['litPic']);
				$product['bigPic'] = imgUrlComplete($product['bigPic']);
				break;
		}

		$this->product     = $product;

		$this->website_url = C('website_url');
		$this->menuID      = '76';
		$this->menuName    = '自由行产品编辑';
		$this->display();
	}

	public function customlist()
	{
		$where   = array();
		$keyword = I('get.keyword');
		$status  = I('get.status','全部');

		$keyword = trimall($keyword);

        if(!empty($keyword))
		{
			$where['_string'] = "(`id` = '".$keyword."' ) OR (`title` LIKE '%".$keyword."%') OR (`libraryProductID` = '".$keyword."')";
		}
		if($status != '全部')$where['status'] = $status;

		$this->status = $status;
		
		$where['type'] = '4';
		$where['status'] = array('neq','-1');
		$product = M2('pack_product_travel')->where($where)->order(array('status'=>'DESC','id'=>'DESC'))->select();
		foreach($product as $key => $value)
		{
			$categoryParentName = M2('pack_product_category')->where(array('id'=>$value['categoryParentID']))->getField('categoryName');
			$categoryChildName  = M2('pack_product_category')->where(array('id'=>$value['categoryChildID']))->getField('categoryName');
			$product[$key]['categoryName'] = $categoryParentName.'/'.$categoryChildName;

			$bigPic = M2('destination_detail')->where(array('pid'=>'5','destination'=>$value['cityID']))->getField('bigPic');

			if(empty($value['litPic']) == true && empty($bigPic) == false)
			{
				$product[$key]['litPic'] = 'http://www.tripvip.cn'.$bigPic;
			}

			$product[$key]['litPic'] = imgUrlComplete($value['litPic']);
			$product[$key]['bigPic'] = imgUrlComplete($value['bigPic']);

		}
		$this->list    	= $product;

		$this->menuID      = '169';
		$this->menuName    = '快速定制产品';
		$this->display();
	}

	public function customAdd()
    {
    	if(IS_POST)
    	{
    		//进销存产品绑定
			$libraryID            = I('post.libraryID');
			$addPriceType         = I('post.addPriceType');
			$addPriceNums         = I('post.addPriceNums');

			$libraryRow = M2('library')->where(array('productID'=>$libraryID,'class'=>array('IN','3,5')))->find();
			if($libraryRow == false)$this->error('此产品不属于自由行或当地游或不存在');

			$data['title']            = $libraryRow['name'];
			$data['libraryID']        = $libraryRow['id'];
			$data['libraryProductID'] = $libraryRow['productID'];
			$data['type']             = 4;
			$data['departureCityID']  = $libraryRow['departureCity'];
			$data['areaID']           = $libraryRow['destinationContinent'];
			$data['countryID']        = $libraryRow['destinationCountry'];
			$data['cityID']           = $libraryRow['destinationCity'];
			$data['price']            = I('post.price');
			$data['gainType']         = $addPriceType;
			$data['gainNums']         = $addPriceNums;
			$data['dateLine']         = time();

			$productID = M3('pack_product_travel')->add($data);

			if($productID != false)
			{
				switch ($addPriceType)
				{
					case '0':
						$library_time = M2('library_time')->where(array('libraryID'=>$libraryRow['id'],'departureTime'=>array('egt',time())))->order('id')->select();
						foreach ($library_time as $key => $value)
						{
							if($value['adultCostPrice'] != false)
							{
								$departureDateData['pid']           = $productID;//................产品ID
								$departureDateData['departuretime'] = $value['departureTime'];
								$departureDateData['price']         = $value['adultCostPrice'];
								$departureDateData['childprice']    = $value['childCostPrice'];
								$departureDateData['seat']          = $value['stockNow'];
								M3('pack_departuredate')->add($departureDateData);
							}
						}
						break;

					case '1':
						$library_time = M2('library_time')->where(array('libraryID'=>$libraryRow['id'],'departureTime'=>array('egt',time())))->order('id')->select();
						foreach ($library_time as $key => $value)
						{
							if($value['adultCostPrice'] != false)
							{
								$departureDateData['pid']           = $productID;//................产品ID
								$departureDateData['departuretime'] = $value['departureTime'];
								$departureDateData['price']         = $value['adultCostPrice'] + $addPriceNums;
								$departureDateData['childprice']    = $value['childCostPrice'] + $addPriceNums;
								$departureDateData['seat']          = $value['stockNow'];
								M3('pack_departuredate')->add($departureDateData);

							}
						}
						break;
					case '2':
						$library_time = M2('library_time')->where(array('libraryID'=>$libraryRow['id'],'departureTime'=>array('egt',time())))->order('id')->select();
						foreach ($library_time as $key => $value)
						{
							if($value['adultCostPrice'] != false)
							{
								$departureDateData['pid']           = $productID;//................产品ID
								$departureDateData['departuretime'] = $value['departureTime'];
								$departureDateData['price']         = $value['adultCostPrice'] + $value['adultCostPrice'] * $addPriceNums;
								$departureDateData['childprice']    = $value['childCostPrice'] + $value['adultCostPrice'] * $addPriceNums;
								$departureDateData['seat']          = $value['stockNow'];
								M3('pack_departuredate')->add($departureDateData);
							}
						}
						break;
				}

				//产品详情
				$detailData['productID']           = $productID;
				$detailData['costInclude']         = $libraryRow['costInclude'];
				$detailData['costNotInclude']      = $libraryRow['costNotInclude'];
				$detailData['reservationNotice']   = $libraryRow['subscribeNotice'];
				$detailData['unreservationNotice'] = $libraryRow['unSubscribeNotice'];
				M3('pack_product_detail')->add($detailData);

				//酒店
				$library_time_hotel = M2('library_time_hotel')->distinct('true')->field('hotelName,hotelStar,hotelAddress,hotelUrl,hotelSingle,hotelUpdate')->where(array('libraryID'=>$libraryRow['id']))->select();
				foreach ($library_time_hotel as $key => $value)
				{
					$hotel = M2('hotel')->where(array('name'=>$value['hotelName']))->find();
					if($hotel != false)
					{
						$hotelManageData['pid']         = $productID;
						$hotelManageData['ids']         = $hotel['id'];
						$hotelManageData['spread']      = $value['hotelSingle'];
						$hotelManageData['updateHotel'] = $value['hotelUpdate'];
						$hotelManageData['dateline']    = time();
						$hotelManageData['updatetime']  = time();
						$hotelManageData['status']      = '1';
						M3('pack_hotel_manage')->add($hotelManageData);
					}
					else
					{
						$hotelData['continent'] = $libraryRow['destinationContinent'];
						$hotelData['country']   = $libraryRow['destinationCountry'];
						$hotelData['city']      = $libraryRow['destinationCity'];
						$hotelData['name']      = $value['hotelName'];
						$hotelData['star']      = $value['hotelStar'];
						$hotelData['address']   = $value['hotelAddress'];
						$hotelData['website']   = $value['hotelUrl'];
						$hotelID = M3('hotel')->add($hotelData);

						$hotelManageData['pid']         = $productID;
						$hotelManageData['ids']         = $hotelID;
						$hotelManageData['spread']      = $value['hotelSingle'];
						$hotelManageData['updateHotel'] = $value['hotelUpdate'];
						$hotelManageData['dateline']    = time();
						$hotelManageData['updatetime']  = time();
						$hotelManageData['status']      = '1';
						M3('pack_hotel_manage')->add($hotelManageData);
					}
				}

				//航班
				$library_time_flight = M2('library_time_flight')->distinct('true')->field('flightType,flightDay,airlineName,flightNumber,departureTime,arrivalTime')->where(array('libraryID'=>$library['id']))->order('id')->select();
				if($library_time_flight != false)
				{
					$flightData['pid']  = $productID;
					$flightData['name'] = '航班参考一';
					$flightID = M3('pack_airplane_flight')->add($flightData);
					foreach ($library_time_flight as $key => $value)
					{
						switch ($value['flightType'])
						{
							case '1':
								$airplaneData['extend'] = '去程';
								break;
							case '2':
								$airplaneData['extend'] = '回程';
								break;
							case '3':
								$airplaneData['extend'] = '转机';
								break;
						}

						$airplaneData['pid']              = $productID;
						$airplaneData['flight_date']      = $flightID;
						$airplaneData['title']            = '第'.$value['flightDay'].'天';
						$airplaneData['flight_info']      = $value['airlineName'];
						$airplaneData['flight_number']    = trim($value['flightNumber']);
						$airplaneData['departure']        = M2('departure')->where(array('id'=>$library['departureCity']))->getField('name');
						$airplaneData['departure_time']   = $value['departureTime'];
						$airplaneData['destination']      = M2('destination')->where(array('id'=>$library['destinationCity']))->getField('name');
						$airplaneData['destination_time'] = $value['arrivalTime'];

						M3('pack_airplane')->add($airplaneData);
					}
				}

				$this->error('添加成功',U(MODULE_NAME.'/Product/sell',array('keyword'=>$productID)));
			}
			else
			{
				$this->error('添加失败');
			}
			exit();
    	}
		$this->menuID   = '169';
		$this->menuName = '快速定制产品添加';
		$this->display();
    }

    public function customEdit()
    {
		$id         = I('get.id');
		$this->id   = $id;
		$step       = I('get.step',0);
		$this->step = $step;

		$productRow = M2('pack_product_travel')->where(array('id'=>$id))->find();
		if($productRow == false)$this->error('此产品不存在');

    	if(IS_POST)
    	{

    		switch ($step)
    		{
    			case '0':
    				$libraryID            = I('post.libraryID');
					$addPriceType         = I('post.addPriceType');
					$addPriceNums         = I('post.addPriceNums');

					$libraryRow = M2('library')->where(array('productID'=>$libraryID,'class'=>array('IN','3,5')))->find();
					if($libraryRow == false)$this->error('此产品不属于自由行或当地游或不存在');

					$data['title']            = $libraryRow['name'];
					$data['libraryID']        = $libraryRow['id'];
					$data['libraryProductID'] = $libraryRow['productID'];
					$data['departureID']      = $libraryRow['departureCity'];
					$data['areaID']           = $libraryRow['destinationContinent'];
					$data['countryID']        = $libraryRow['destinationCountry'];
					$data['cityID']           = $libraryRow['destinationCity'];
					$data['gainType']         = $addPriceType;
					$data['gainNums']         = $addPriceNums;

					$result = M3('pack_product_travel')->where(array('id'=>$productRow['id']))->save($data);
					if($result != false)
					{
						M3('pack_departuredate')->where(array('pid'=>$productRow['id']))->delete();

						switch ($addPriceType)
						{
							case '0':
								$library_time = M2('library_time')->where(array('libraryID'=>$libraryRow['id'],'departureTime'=>array('egt',time())))->select();
								foreach ($library_time as $key => $value)
								{
									if($value['adultCostPrice'] != false)
									{
										$departureDateData['pid']           = $productID;//................产品ID
										$departureDateData['departuretime'] = $value['departureTime'];
										$departureDateData['price']         = $value['adultCostPrice'];
										$departureDateData['childprice']    = $value['childCostPrice'];
										$departureDateData['seat']          = $value['stockNow'];
										M3('pack_departuredate')->add($departureDateData);
									}
								}
								break;

							case '1':
								$library_time = M2('library_time')->where(array('libraryID'=>$libraryIDArr['id'],'departureTime'=>array('egt',time())))->select();
								foreach ($library_time as $key => $value)
								{
									if($value['adultCostPrice'] != false)
									{
										$departureDateData['pid']           = $productID;//................产品ID
										$departureDateData['departuretime'] = $value['departureTime'];
										$departureDateData['price']         = $value['adultCostPrice'] + $addPriceNums;
										$departureDateData['childprice']    = $value['childCostPrice'] + $addPriceNums;
										$departureDateData['seat']          = $value['stockNow'];
										M3('pack_departuredate')->add($departureDateData);

									}
								}
								break;
							case '2':
								$library_time = M2('library_time')->where(array('libraryID'=>$libraryIDArr['id'],'departureTime'=>array('egt',time())))->select();
								foreach ($library_time as $key => $value)
								{
									if($value['adultCostPrice'] != false)
									{
										$departureDateData['pid']           = $productID;//................产品ID
										$departureDateData['departuretime'] = $value['departureTime'];
										$departureDateData['price']         = $value['adultCostPrice'] + $value['adultCostPrice'] * $addPriceNums;
										$departureDateData['childprice']    = $value['childCostPrice'] + $value['adultCostPrice'] * $addPriceNums;
										$departureDateData['seat']          = $value['stockNow'];
										M3('pack_departuredate')->add($departureDateData);
									}
								}
								break;
						}
					}

					break;
				case '1':
    				$data['costInclude'] = I('post.costInclude','', 'trim');
					$result = M3('pack_product_detail')->where(array('productID'=>$productRow['id']))->save($data);
    				break;
    			case '2':
    				$data['costNoclude'] = I('post.costNoclude','', 'trim');
					$result = M3('pack_product_detail')->where(array('productID'=>$productRow['id']))->save($data);
    				break;
    			case '3':
    				$data['reservationNotice'] = I('post.reservationNotice','', 'trim');
					$result = M3('pack_product_detail')->where(array('productID'=>$productRow['id']))->save($data);
    				break;
    			case '4':
    				$data['unreservationNotice'] = I('post.unreservationNotice','', 'trim');
					$result = M3('pack_product_detail')->where(array('productID'=>$productRow['id']))->save($data);
    				break;
    		}
    		if($result != alse)
    		{
    			$this->success('修改成功！');
    		}
    		else
    		{
    			$this->error('修改失败！');
    		}
    	}

    	$price = M2('library_time')->where(array('libraryID'=>$productRow['libraryID'],'departureTime'=>array('gt',time()),'adultCostPrice'=>array('neq','0')))->order('id')->getField('adultCostPrice');

    	// var_dump($price);
    	switch ($productRow['gainType'])
    	{
    		case '0':
    			$productRow['sellPrice'] = ceil($price);
    			break;
    		case '1':
    			$productRow['sellPrice'] = ceil($price + $productRow['gainNums']);
    			break;
    		case '2':
    			$productRow['sellPrice'] = ceil($price + ($price * $productRow['gainNums'] * 0.01));
    			break;
    	}
    	$productRow['costPrice'] = $price;
		$this->detail = M2('pack_product_detail')->where(array('productID'=>$productRow['id']))->find();
		$this->product = $productRow;

    	$this->menuID   = '169';
		$this->menuName = '快速定制产品编辑';
		$this->display();
    }

    /**
     * [getLibraryAjax description]
     * @return [type] [description]
     */
    public function getLibraryAjax()
    {
		$data      = array('valid'=>false);
		$libraryID = I('post.libraryID');
		$result    = M2('library')->where(array('productID'=>$libraryID,'status'=>'1'))->find();
    	if($result != false)
    	{
			$data['departureName'] = M2('departure')->where(array('id'=>$result['departureCity']))->getField('name');
			$data['libraryTitle']  = $result['name'];
			$data['price']         = M2('library_time')->where(array('libraryID'=>$result['id'],'departureTime'=>array('gt',time()),'adultCostPrice'=>array('neq','0')))->order('id')->getField('adultCostPrice');
			// echo M2('library_time')->getlastsql();
			if($data['price'] != false)$data['valid'] = true;

    	}
    	else
    	{
    		$data['valid'] = false;
    	}

    	$this->ajaxReturn($data);
    }

    /**
     * [checkDeparture description]
     * @return [type] [description]
     */
    public function checkDepartureAjax()
    {
    	$productID = I('post.productID');
    	$result = M2('pack_departuredate')->where(array('pid'=>$productID,'departuretime'=>array('gt',time()),'seat'=>array('gt','0')))->find();
    	if($result == false)
    	{
    		$data['valid'] = false;
    		$data['state'] = '请添加出团时间';
    	}
    	else
    	{
    		$data['valid'] = true;
    	}
    	$this->ajaxReturn($data);
    }

    /**
     * 直销产品分类
     * @return [type] [description]
     */
    public function sellcategory()
    {
    	$list = M2('pack_product_classlabel')->where(array('pId'=>'0'))->order('sort')->select();

    	foreach ($list as $key => $value)
    	{
    		$list[$key]['categoryTwo'] = M2('pack_product_classlabel')->where(array('pId'=>$value['id']))->order('sort')->select();

    		foreach ($list[$key]['categoryTwo'] as $k => $v)
    		{
    			$list[$key]['categoryTwo'][$k]['label'] = M2('pack_product_classlabel')->where(array('pId'=>$v['id']))->select();
    		}
    	}

    	$this->list = $list;
    	$this->menuID   = '77';
		$this->menuName = '直销产品分类';
    	$this->display();
    }

	/**
	 * [destinationDataAjax description]
	 * @return [type] [description]
	 */
	public function destinationDataAjax()
	{
		$destinationID = I('post.destinationID');

		if($destinationID)
		{
			$data['destinationChildHtml'] = destinationChildHtml($destinationID);
		}

		$this->ajaxReturn($data);
	}
	/**
	 * [packCategoryAjax description]主站类型返回
	 * @return [type] [description]
	 */
	public function packCategoryAjax()
	{
		$packCategoryOne = I('get.packCategoryOne');

		$categoryArrTwo = M2('pack_product_classlabel')->where(array('pId'=>$packCategoryOne))->order('id')->select();
		$html = '';
		$html .= '<select name="packCategoryTwo" onChange="categoryLabelList(this)">';
		$html .= '<option value="0">请选择</option>';
		foreach ($categoryArrTwo as $key => $value)
		{

			$html .= '<option value="'.$value['id'].'" >'.$value['name'].'</option>';

		}
        $html .= '</select>';
        $data['html'] = $html;
        $this->ajaxReturn($data);
	}
	/**
	 * [submitContain description]添加新增单品
	 * @return [type] [description]
	 */
	public function submitContain()
	{
		$id                = I('post.id',0);

		$add['productID'] = I('post.productID');
		$add['img']       = I('post.img');
		$add['name']      = I('post.name');
		$add['content']   = I('post.content');

		if($id == 0)
		{

			$result = M3('pack_product_contain')->add($add);
		}
		else
		{
			$result = M3('pack_product_contain')->where(array('id'=>$id))->save($add);
		}
		if($result !== false)
		{
			$data['status'] = true;
		}
		else
		{
			$data['status'] = false;
		}
		$this->ajaxReturn($data);
	}
	/**
	 * [delContain description]新增单品删除
	 * @return [type] [description]
	 */
	public function delContain()
	{
		$id = I('get.id');

		$result = M3('pack_product_contain')->where(array('id'=>$id))->delete();
		if($result !== false)
		{
			$this->success('删除成功！');
		}
		else
		{
			$this->error('删除失败！');
		}
	}

	/**
	 * [submitGifts description]
	 * @return [type] [description]
	 */
	public function submitGifts()
	{
		$id               = I('post.id',0);

		$add['productID'] = I('post.productID');
		$add['img']       = I('post.img');
		$add['name']      = I('post.name');
		$add['price']     = I('post.price');
		$add['content']   = I('post.content');

		if($id == 0)
		{

			$result = M3('pack_product_gifts')->add($add);
		}
		else
		{
			$result = M3('pack_product_gifts')->where(array('id'=>$id))->save($add);
		}
		if($result !== false)
		{
			$data['status'] = true;
		}
		else
		{
			$data['status'] = false;
		}
		$this->ajaxReturn($data);
	}

	/**
	 * [delGifts description]
	 * @return [type] [description]
	 */
	public function delGifts()
	{
		$id = I('get.id');

		$result = M3('pack_product_gifts')->where(array('id'=>$id))->delete();
		if($result !== false)
		{
			$this->success('删除成功！');
		}
		else
		{
			$this->error('删除失败！');
		}
	}
	/**
	 * [sellRecommendSet description]
	 * @return [type] [description]
	 */
	public function sellRecommendSet()
	{
		$id   = I('get.id');
		$type = I('get.type');

		$data['recommend'] = $type;
		$result = M3('pack_product_travel')->where(array('id'=>$id))->save($data);
		if($result !== false)
		{
			$this->success('成功！');
		}
		else
		{
			$this->error('失败！');
		}
	}

	/**
	 * [sellStatusSet description]
	 * @return [type] [description]
	 */
	public function sellStatusSet()
	{
		if(IS_POST)
		{
			$id              = I('post.id');
			$data['status']  = I('post.status');
			$data['endDate'] = strtotime(I('post.endDate'));
		}

		if(IS_GET)
		{
			$id             = I('get.id');
			$data['status'] = I('get.status');
		}

		$result = M3('pack_product_travel')->where(array('id'=>$id))->save($data);
		if($result != false)
		{
			$this->success('修改状态成功！');
		}
		else
		{
			$this->error('修改状态失败！');
		}
		exit;
	}
	/**
	 * [categoryLabelList description]主站分类标签列表
	 * @return [type] [description]
	 */
	public function categoryLabelList()
	{
		$id = I('get.id');

		$list = M2('pack_product_classlabel')->where(array('pId'=>$id))->select();
		$html = '';
		foreach ($list as $key => $value)
		{
			$html .= '<input type="checkbox" name="categorylabel[]" value="'.$value['id'].'" style="margin-left: 10px;" />'.$value['name'];
		}
		$data['html'] = $html;
		$this->ajaxReturn($data);
	}
	/**
	 * [submitAddProduct description]附加产品添加和修改
	 * @return [type] [description]
	 */
	public function submitAddProduct()
	{

		$id               = I('post.id',0);

		$add['productID'] = I('post.productID');
		$add['img']       = I('post.img');
		$add['name']      = I('post.name');
		$add['price']     = I('post.price');
		$add['sumType']   = I('post.sumType');
		$add['price']     = I('post.price');
		$add['content']   = I('post.content');

		if($id == 0)
		{

			$result = M3('pack_addproduct')->add($add);
		}
		else
		{
			$result = M3('pack_addproduct')->where(array('id'=>$id))->save($add);
		}
		if($result !== false)
		{
			$data['status'] = true;
		}
		else
		{
			$data['status'] = false;
		}
		$this->ajaxReturn($data);
	}
	/**
	 * [delAddProduct description]附加产品删除
	 * @return [type] [description]
	 */
	public function delAddProduct()
	{
		$id = I('get.id');

		$result = M3('pack_addproduct')->where(array('id'=>$id))->delete();

		if($result !== false)
		{
			$this->success('成功！');
		}
		else
		{
			$this->error('失败！');
		}
	}

	/**
	 * [sellrecommend description]
	 * 首页推荐管理
	 * @return [type] [description]
	 */
	public function sellrecommend()
	{
		$list = M2('pack_category_recommend_info')->order('id')->select();
		foreach ($list as $key => $value)
		{
			$list[$key]['title'] = M2('pack_product_travel')->where(array('id'=>$value['productID']))->getField('title');
			$list[$key]['categoryName'] = M2('pack_recommend_category')->where(array('id'=>$value['categoryID']))->getField('name');
		}
		$this->list     = $list;

		$this->menuID   = '78';
		$this->menuName = '首页推荐管理';
		$this->display();
	}

	/**
	 * [sellrecommendadd description]
	 * 推荐产品添加
	 * @return [type] [description]
	 */
	public function sellrecommendadd()
	{
		if(IS_POST)
		{
			$data['productID']   = I('post.productID');
			$data['categoryID']  = I('post.categoryID');
			$data['description'] = I('post.description');
			// var_dump($data);exit;
			$result = M3('pack_category_recommend_info')->add($data);
			if($result !== false)
			{
				$this->success('添加成功！',U(MODULE_NAME. '/Product/sellrecommend'));
			}
			else
			{
				$this->error('添加失败！');
			}
			exit;
		}
		$categoryList       = M2('pack_recommend_category')->select();

		$this->categoryList = $categoryList;
		$this->menuID       = '78';
		$this->menuName     = '推荐产品添加';
		$this->display();
	}

	/**
	 * [sellrecommendcategoryadd description]
	 * @return [type] [description]
	 */
	public function sellrecommendcategoryadd()
	{
		if(IS_POST)
		{
			$data['name']  = I('post.name');
			$data['color'] = I('post.color');
			$data['img']   = I('post.img');
			$data['sort']  = I('post.sort');


			$result = M3('pack_recommend_category')->add($data);
			if($result != false)
			{
				$this->success('添加成功！',U(MODULE_NAME. '/Product/sellrecommend'));
			}
			else
			{
				$this->error('添加失败！');
			}
			exit;
		}

		$this->menuID   = '78';
		$this->menuName = '推荐分类添加';
		$this->display();
	}
	/**
	 * [productData description]
	 * @return [type] [description]
	 */
	public function productData()
	{
		$id = I('post.id');
		$data['title'] = M2('pack_product_travel')->where(array('id'=>$id))->getField('title');
		if($data['title'] != false)
		{
			$data['msg'] = true;
		}
		else
		{
			$data['msg'] = false;
		}
		$this->ajaxReturn($data);
	}
	/**
	 * [sellrecommendedit description]
	 * @param  string $value [description]
	 * @return [type]        [description]
	 */
	public function sellrecommendedit()
	{
		$id                  = I('post.id');
		$data['productID']   = I('post.productID');
		$categoryName        = I('post.categoryName');
		$data['description'] = I('post.description');
		$productID   = M2('pack_product_travel')->where(array('id'=>$data['productID']))->getField('id');
		if($productID != false)
		{

			$categoryID = M2('pack_recommend_category')->where(array('name'=>$categoryName))->getField('id');
			if($categoryID != false)
			{
				$data['categoryID'] = $categoryID;

				$result = M3('pack_category_recommend_info')->where(array('id'=>$id))->save($data);
				if($result != false)
				{
					$data['msg'] = true;
				}
				else
				{
					$data['msg'] = '修改失败';
				}
			}
			else
			{
				$data['msg'] = '没有找到填写的类名';
			}
		}
		else
		{
			$data['msg'] = '没有找填写的产品';
		}
		$this->ajaxReturn($data);
	}
	/**
	 * [sellrecommenddel description]
	 * @return [type] [description]
	 */
	public function sellrecommenddel()
	{
		$id = I('get.id');

		$result = M3('pack_category_recommend_info')->where(array('id'=>$id))->delete();

		if($result != false)
		{
			$this->success('删除成功！',U(MODULE_NAME. '/Product/sellrecommend'));
		}
		else
		{
			$this->error('删除失败！');
		}
	}

	/**
	 * [sellrecommendcategorylist description]
	 * @return [type] [description]
	 */
	public function sellrecommendcategorylist()
	{
		$list           = M2('pack_recommend_category')->select();

		$this->list     = $list;
		$this->menuID   = '78';
		$this->menuName = '推荐产品分类列表';
		$this->display();
	}

	/**
	 * [sellrecommendcategoryedit description]
	 * @return [type] [description]
	 */
	public function sellrecommendcategoryedit()
	{
		$id       = I('get.id');
		$this->id = $id;
		if(IS_POST)
		{
			$data['name']  = I('post.name');
			$data['img']   = I('post.img');
			$data['color'] = I('post.color');
			$data['sort']  = I('post.sort');
			$result = M3('pack_recommend_category')->where(array('id'=>$id))->save($data);

			if($result != false)
			{
				$this->success('修改成功！',U(MODULE_NAME. '/Product/sellrecommendcategorylist'));
			}
			else
			{
				$this->error('修改失败！');
			}
			exit;
		}
		$category       = M2('pack_recommend_category')->where(array('id'=>$id))->find();
		$this->category = $category;
		$this->menuID   = '78';
		$this->menuName = '推荐产品分类修改';
		$this->display();
	}

	/**
	 * [sellrecommendcategorydel description]
	 * @return [type] [description]
	 */
	public function sellrecommendcategorydel()
	{
		$id = I('get.id');

		$result = M3('pack_recommend_category')->where(array('id'=>$id))->delete();

		if($result != false)
		{
			$this->success('删除成功！',U(MODULE_NAME. '/Product/sellrecommendcategorylist'));
		}
		else
		{
			$this->error('删除失败！');
		}
	}

	/**
	 * [sellcategoryedit description]
	 * @return [type] [description]
	 */
	public function sellcategoryedit()
	{
		$id         = I('get.id');
		$this->id   = $id;

		if(IS_POST)
		{
			$data['name']     = I('post.name');
			$data['describe'] = I('post.describe');
			$data['keywords'] = I('post.keywords');
			$data['sort']     = I('post.sort');
			$result = M3('pack_product_classlabel')->where(array('id'=>$id))->save($data);
			if($result != false)
			{
				$this->success('修改成功！',U(MODULE_NAME. '/Product/sellcategory'));
			}
			else
			{
				$this->error('修改失败！');
			}
			exit;
		}

		$list = M2('pack_product_classlabel')->where(array('id'=>$id))->find();

		$this->list = $list;
		$this->menuID   = '77';
		$this->menuName = '直销产品标签修改';
		$this->display();
	}
	/**
	 * [sellproductdel description]直销产品删除
	 * @return [type] [description]
	 */
	public function sellproductdel()
	{
		$id     = I('get.id');
		$result = M3('pack_product_travel')->where(array('id'=>$id))->save(array('status'=>'-1'));
		if($result != false)
		{
			//产品表cms_product->cms_pack_product
			//产品详情cms_product_detail->cms_pack_product_detail
			//产品亮点cms_product_highlight->cms_pack_product_highlight
			//产品行程cms_product_travelreference->cms_pack_product_travelreference
			//产品出行日期cms_departure_time->cms_pack_departuredate
			//产品航班cms_airplane->cms_pack_airplane
			//产品酒店cms_hotel_manage->cms_pack_hotel_manage
			//棉签妹推荐表cms_pack_recommend_reson
			//包含单品表cms_pack_product_contain
			//赠送单品表cms_pack_product_gifts

			/*M3('pack_product_detail')->where(array('productID'=>$id))->delete();
			M3('pack_product_highlight')->where(array('productID'=>$id))->delete();
			M3('pack_product_travelreference')->where(array('productID'=>$id))->delete();
			M3('pack_departuredate')->where(array('pid'=>$id))->delete();
			M3('pack_airplane')->where(array('pid'=>$id))->delete();
			M3('pack_hotel_manage')->where(array('pid'=>$id))->delete();
			M3('pack_recommend_reson')->where(array('productID'=>$id))->delete();
			M3('pack_product_contain')->where(array('productID'=>$id))->delete();
			M3('pack_product_gifts')->where(array('productID'=>$id))->delete();
			M3('pack_addproduct')->where(array('productID'=>$id))->delete();*/

			$this->success('删除成功！');
		}
		else
		{
			$this->error('删除失败！');
		}
	}

	/**
	 * [localtravel description]
	 * 当地游产品列表
	 * @return [type] [description]
	 */
	public function localtravel()
	{
		$where         = array();
		$keyword       = I('get.keyword');
		$status        = I('get.status','全部');
		$where['type'] = '2';
		if($status != '全部')
		{
			$where['status'] = $status;
		}

		$this->status = $status;

		$keyword = trimall($keyword);

        if(!empty($keyword))
		{
			if(eregi('^[0-9]*$',$keyword))
			{
				$where['id'] = array('eq',$keyword);
			}
			else
			{
				$where['title'] = array('like',"%$keyword%");
			}
		}

		$count     = M2('pack_product_travel')->where($where)->count();
		$PageClass = new \Think\Page($count,10);
		$page      = $PageClass->show();
		$list      = M2('pack_product_travel')->where($where)->limit($PageClass->firstRow.','.$PageClass->listRows)->order('id DESC')->select();
		foreach($list as $key => $value)
		{

			$categoryParentName = M2('pack_product_category')->where(array('id'=>$value['categoryParentID']))->getField('categoryName');
			$categoryChildName  = M2('pack_product_category')->where(array('id'=>$value['categoryChildID']))->getField('categoryName');
			$list[$key]['categoryName'] = $categoryParentName.'/'.$categoryChildName;
			$list[$key]['supplierName'] = M('supplier')->where(array('id' => $value['supplierID']))->getField('name');
		}
		$this->keyword  = $keyword;
		$this->page     = $page;

		$this->list     = $list;
		$this->menuID   = '80';
		$this->menuName = '当地有产品列表';
		$this->display();
	}

	/**
	 * [localtravel description]
	 * 当地游产品添加
	 * @return [type] [description]
	 */
	public function localtraveladd()
	{

		if(IS_POST)
		{
			$data['title']              = I('post.title');
			$data['categoryInterestID'] = implode('|', I('post.catID',array()));
			$data['verify']             = I('post.verify',1);
			$data['extend']             = I('post.extend');
			$data['areaID']             = I('post.areaID');
			$data['countryID']          = I('post.countryID');
			$data['cityID']             = I('post.cityID');
			$data['departureDate']      = I('post.departureDate');
			$data['travelDays']         = I('post.travelDays');
			$data['travelNight']        = I('post.travelNight');
			$data['marketPrice']        = I('post.marketPrice');
			$data['price']              = I('post.price');
			$data['litPic']             = I('post.litPic');
			$originalImages             = I('post.bigPic');
			if(empty($originalImages) == false)
			{
				$data['bigPic']             = $originalImages;
			    $data['mobileBigPic'] 		= originalImagesMobile($originalImages);
			}
			$data['keyWords']           = I('post.keyWords');
			$data['type']               = '2';
			$data['dateLine']           = time();
			$data['adduserID']          = getIdenty();

			$productID = M3('pack_product_travel')->add($data);
			if($productID !== false)
			{

				$categoryParentID = I('post.categoryID');
				$categoryChildID  = I('post.packCategoryTwo');
				$categoryLabelID  = I('post.categorylabel',array());

				$labelCount = count($categoryLabelID);

				for ($i = 0; $i < $labelCount; $i++)
				{
					$labelData['productID']        = $productID;
					$labelData['categoryParentID'] = $categoryParentID;
					$labelData['categoryChildID']  = $categoryChildID;
					$labelData['categoryLabelID']  = $categoryLabelID[$i];
					M3('pack_product_label')->add($labelData);
				}

				//产品亮点
				for ($i=0; $i < 4; $i++)
				{
					$highlightData['productID'] = $productID;
					$highlightData['sort'] = $i+1;
					M3('pack_product_highlight')->add($highlightData);
				}

				//费用说明
				//预订须知
				//温馨提示
				$detailData['productID'] = $productID;
				M3('pack_product_detail')->add($detailData);

				$this->success('添加产品成功！',U(MODULE_NAME. '/Product/sell'));
			}
			else
			{
				$this->error('添加产品失败！');
			}
			exit;

		}

		//所属兴趣分类
		$catArr       = M2('product_category')->where(array('isshow'=>'1'))->order('id,sort')->select();
		$this->catArr = $catArr;

		//主站分类
		//分类标签
		$categoryArr       = M2('pack_product_classlabel')->where(array('pId'=>'0'))->select();
		$this->categoryArr = $categoryArr;

		//目的地
		$destinationArr    = M2('destination')->where(array('pid'=>'0'))->select();
		$this->destinationArr = $destinationArr;

		$this->menuID   = '76';
		$this->menuName = '当地有产品添加';
		$this->display();
	}

	/**
	 * [localtraveledit description]
	 * 当地游产品编辑
	 * @return [type] [description]
	 */
	public function localtraveledit()
	{
		$id         = I('get.id');
		$this->id   = $id;
		$step       = I('get.step',0);
		$this->step = $step;

		if(IS_POST)
		{
			switch ($step)
			{
				case '0':
					$data['title']              = I('post.title');
					$data['categoryInterestID'] = implode('|', I('post.catID',array()));
					$data['verify']             = I('post.verify',1);
					$data['extend']             = I('post.extend');
					$data['areaID']             = I('post.continent',array())['0'];
					$data['countryID']          = I('post.country',array())['0'];
					$data['cityID']             = I('post.city',array())['0'];
					$data['departureDate']      = I('post.departureDate');
					$data['travelDays']         = I('post.travelDays');
					$data['travelNight']        = I('post.travelNight');
					$data['marketPrice']        = I('post.marketPrice');
					$data['price']              = I('post.price');
					$data['litPic']             = I('post.litPic');
					$originalImages             = I('post.bigPic');
					if(empty($originalImages) == false)
					{

						$data['bigPic']             = $originalImages;
					    $data['mobileBigPic'] 		= originalImagesMobile($originalImages);
					}
					$data['keyWords']           = I('post.keyWords');

					/*if(imgUrlComplete($product['litPic']) != $data['litPic'])
					{
						delImg($product['litPic']);
					}
					if(imgUrlComplete($product['bigPic']) != $data['bigPic'])
					{
						delImg($product['bigPic']);
					}
					if(imgUrlComplete($product['mobileBigPic']) != $data['mobileBigPic'])
					{
						delImg($product['mobileBigPic']);
					}*/

					$result = M3('pack_product_travel')->where(array('id'=>$id))->save($data);


					$categoryParentID = I('post.categoryID');
					$categoryChildID  = I('post.packCategoryTwo');
					$categorylabelArr = I('post.categorylabel',array());

					$labelArr         = M2('pack_product_label')->where(array('productID'=>$id))->select();
					$labelCount       = count($categorylabelArr);
					$existsLabelCount = count($labelArr);
					if($labelCount == $existsLabelCount)
					{
						foreach ($labelArr as $key => $value)
						{
							$labelData['categoryParentID'] = $categoryParentID;
							$labelData['categoryChildID']  = $categoryChildID;
							$labelData['categoryLabelID']  = $categorylabelArr[$key];
							M3('pack_product_label')->where(array('id'=>$value['id']))->save($labelData);
						}
					}
					else if($labelCount > $existsLabelCount)
					{
						foreach ($labelArr as $key => $value)
						{
							$labelData['categoryParentID'] = $categoryParentID;
							$labelData['categoryChildID']  = $categoryChildID;
							$labelData['categoryLabelID']  = $categorylabelArr[$key];
							M3('pack_product_label')->where(array('id'=>$value['id']))->save($labelData);
						}

						for ($i=0; $i < ($labelCount - $existsLabelCount); $i++)
						{
							$labelData['productID']        = $id;
							$labelData['categoryParentID'] = $categoryParentID;
							$labelData['categoryChildID']  = $categoryChildID;
							$labelData['categoryLabelID']  = $categorylabelArr[$i+$existsLabelCount];

							M3('pack_product_label')->add($labelData);
						}
					}
					else if($labelCount < $existsLabelCount)
					{
						foreach ($labelArr as $key => $value)
						{
							if(($key+1) > $labelCount)
							{
								M3('pack_product_label')->where(array('id'=>$value['id']))->delete();
							}
							else
							{

								$labelData['categoryParentID'] = $categoryParentID;
								$labelData['categoryChildID']  = $categoryChildID;
								$labelData['categoryLabelID']  = $categorylabelArr[$key];
								M3('pack_product_label')->where(array('id'=>$value['id']))->save($labelData);
							}
						}
					}


					break;
				case '1':
					$content     = I('post.content',array());
					$reson       = I('post.reson',array());
					$highlightID = I('post.highlightID',array());
					$count = count($content);
					for ($i=0; $i < $count; $i++)
					{
						$data['content'] = $content[$i];
						$data['reson']   = $reson[$i];
						$result = M3('pack_product_highlight')->where(array('id'=>$highlightID[$i],'productID'=>$id))->save($data);
					}
					break;
				case '2':
					$data['costInclude'] = I('post.costInclude', '', 'trim');
					$result = M3('pack_product_detail')->where(array('productID'=>$id))->save($data);
					break;
				case '3':
					$data['reservationNotice'] = I('post.reservationNotice', '', 'trim');
					$result = M3('pack_product_detail')->where(array('productID'=>$id))->save($data);
					break;
				case '4':
					$data['warmReminder'] = I('post.warmReminder', '', 'trim');
					$result = M3('pack_product_detail')->where(array('productID'=>$id))->save($data);
					break;
				case '5':
					$data['couponID'] = implode('|', I('post.coupon',array()));
					$result = M3('pack_product_travel')->where(array('id'=>$id))->save($data);
					break;
				case '6':
					$data['recommend']              = I('post.recommend');
					$data['headerImg']              = I('post.headerImg');
					$data['reson']                  = I('post.reson');
					$data['recommendHotleReson']    = I('post.recommendHotleReson');
					$data['recommendAirplaneReson'] = I('post.recommendAirplaneReson');
					$find = M2('pack_recommend_reson')->where(array('productID'=>$id))->find();
					if($find == false)
					{
						$data['productID'] = $id;
						$result = M3('pack_recommend_reson')->add($data);
					}
					else
					{
						$result = M3('pack_recommend_reson')->where(array('productID'=>$id))->save($data);
					}
					break;

				default:
					# code...
					break;
			}

			if($result !== false)
			{
				$this->success('修改产品成功！');
			}
			else
			{
				$this->error('修改产品失败！');
			}
			exit;
		}


		//产品基本信息
		$product = M2('pack_product_travel')->where(array('id'=>$id,'type'=>'2'))->find();

		switch ($step)
		{
			case '0':
				//产品所选兴趣分类
				$catCheckArr = explode('|', $product['categoryInterestID']);
				//所属兴趣分类
				$catArr       = M2('product_category')->where(array('isshow'=>'1'))->order('id,sort')->select();
				foreach ($catArr as $key => $value)
				{
					if(in_array($value['id'],$catCheckArr) == true)
					{
						$catArr[$key]['checked'] = 'checked';
					}
				}
				$this->catArr = $catArr;

				//主站分类
				$classRow = M2('pack_product_label')->where(array('productID'=>$product['id']))->find();

				$categoryOneArr = M2('pack_product_classlabel')->where(array('pId'=>'0'))->select();
				$categoryHtmlOne = '';
				$categoryHtmlOne .= '<select name="categoryID" onchange="packCategory(this)">';
				$categoryHtmlOne .= '<option value="0">请选择</option>';
				foreach ($categoryOneArr as $key => $value)
				{
					if($value['id'] == $classRow['categoryParentID'])
					{
						$categoryHtmlOne .= '<option value="'.$value['id'].'" selected >'.$value['name'].'</option>';
					}
					else
					{
						$categoryHtmlOne .= '<option value="'.$value['id'].'" >'.$value['name'].'</option>';
					}
				}
				$categoryHtmlOne .= '</select>';
				$this->categoryHtmlOne = $categoryHtmlOne;


				$categoryTwoArr = M2('pack_product_classlabel')->where(array('pId'=>$classRow['categoryParentID']))->select();

				$categoryHtmlTwo = '';
				$categoryHtmlTwo .= '<select name="packCategoryTwo" onchange="categoryLabelList(this)">';
				$categoryHtmlTwo .= '<option value="0">请选择</option>';
				foreach ($categoryTwoArr as $key => $value)
				{
					if($value['id'] == $classRow['categoryChildID'])
					{
						$categoryHtmlTwo .= '<option value="'.$value['id'].'" selected >'.$value['name'].'</option>';
					}
					else
					{
						$categoryHtmlTwo .= '<option value="'.$value['id'].'" >'.$value['name'].'</option>';
					}
				}
				$categoryHtmlTwo .= '</select>';
				$this->categoryHtmlTwo = $categoryHtmlTwo;


				//主站分类标签
				$currLabelArr = M2('pack_product_label')->field('categoryLabelID')->where(array('productID'=>$product['id']))->select();
				$currLabel = array();
				foreach ($currLabelArr as $key => $value)
				{
					$currLabel[$key] = $value['categoryLabelID'];
				}

				if(empty($currLabel) == false)
				{
					$categorylabelArr = M2('pack_product_classlabel')->field('id,name')->where(array('pId'=>$classRow['categoryChildID']))->select();
					$categorylabelHtml = '';
					foreach ($categorylabelArr as $key => $value)
					{
						if(in_array($value['id'],$currLabel) == true)
						{
							$categorylabelHtml .= '<input type="checkbox" name="categorylabel[]" checked value="'.$value['id'].'" style="margin-left: 10px;">'.$value['name'];
						}
						else
						{
							$categorylabelHtml .= '<input type="checkbox" name="categorylabel[]" value="'.$value['id'].'" style="margin-left: 10px;">'.$value['name'];
						}
					}
					$this->categorylabelHtml = $categorylabelHtml;
				}


				//目的地
				$areaID    = explode(",",$product['areaID']);
				$countryID = explode(",",$product['countryID']);
				$cityID    = explode(",",$product['cityID']);

				$array_continent = M2('destination')->field('id,name')->where(array('pid'=>0))->order('sort, id')->select();
				$this->destination_continent = areaSelect('', $array_continent, "请选择大洲" );;
				$continent = '';
				foreach ($areaID as $key => $value)
				{
					$continent .= '<div><select name="continent[]" style="float:left;" onchange="destination(this,1)">';
					$continent .= areaSelect($areaID[$key], $array_continent, "请选择大洲" );
					$continent .= '</select>';
					$array_country = M2('destination')->field('id,name')->where(array('pid'=>$areaID[$key]))->order('sort, id')->select();
					$continent .= '<select name="country[]" style="float:left;" onchange="destination(this,2)">';
					$continent .= areaSelect($countryID[$key], $array_country, "请选择国家" );
					$continent .= '</select>';
					$array_city = M2('destination')->field('id,name')->where(array('pid'=>$countryID[$key]))->order('sort, id')->select();
					$continent .= '<select name="city[]" style="float:left;">';
					$continent .= areaSelect($cityID[$key], $array_city, "请选择城市" );
					$continent .= '</select>';
					$continent .= '</div>';
				}
				$this->destination = $continent;

				$product['litPic'] = imgUrlComplete($product['litPic']);
				$product['bigPic'] = imgUrlComplete($product['bigPic']);

				break;
			case '1':
				//产品亮点
				$highlight = M2('pack_product_highlight')->where(array('productID'=>$product['id']))->order('sort')->select();
				$this->highlight = $highlight;
				break;
			case '2':
				//费用包含
				$costInclude = M2('pack_product_detail')->where(array('productID'=>$product['id']))->getField('costInclude');
				$this->costInclude = $costInclude;
				break;
			case '3':
				//预订须知
				$reservationNotice = M2('pack_product_detail')->where(array('productID'=>$product['id']))->getField('reservationNotice');
				$this->reservationNotice = $reservationNotice;
				break;
			case '4':
				//温馨提示
				$warmReminder = M2('pack_product_detail')->where(array('productID'=>$product['id']))->getField('warmReminder');
				$this->warmReminder = $warmReminder;
				break;
			case '5':

				//优惠券
				$coupontypeart = M2('coupons_mould')->field('*')->order('id')->select();
				$array   = explode('|', $product['couponID']);
				foreach($coupontypeart as $key => $value)
				{
					$category = M2('coupons_category')->find($value['category_id']);
					$name = M2('coupons_cooperation')->find($value['cp_id']);
					$coupontypeart[$key]['category'] = $category['category_name'];
					$coupontypeart[$key]['name'] = $name['cooperative'];
					$coupontypeart[$key]['amount'] = $value['face_amount'];

					if(in_array($value['id'], $array))
					{
						$coupontypeart[$key]['checked'] = ' checked="checked" ';
						$coupontypeart[$key]['picture_item2'] = ' picture_item2 ';
					}

				}
				$this->coupontypelist = $coupontypeart;
				break;
			case '6':
				//棉签妹推荐
				$personRecommend = M2('pack_recommend_reson')->where(array('productID'=>$product['id']))->find();
				$personRecommend['headerImg'] = imgUrlComplete($personRecommend['headerImg']);
				$this->personRecommend = $personRecommend;
				break;
			case '7':
				//包含单品
				$contain = M2('pack_product_contain')->where(array('productID'=>$product['id']))->select();
				foreach ($contain as $key => $value)
				{
					$contain[$key]['img'] = imgUrlComplete($value['img']);
				}
				$this->contain = $contain;
				break;
			case '8':
				//赠送单品
				$gifts = M2('pack_product_gifts')->where(array('productID'=>$product['id']))->select();
				foreach ($gifts as $key => $value)
				{
					$gifts[$key]['img'] = imgUrlComplete($value['img']);
				}
				$this->gifts = $gifts;
				break;
		}
		$this->product     = $product;
		$this->website_url = C('website_url');
		$this->menuID      = '76';
		$this->menuName    = '当地有产品编辑';
		$this->display();
	}

	/**
	 * [actlist description]活动管理列表
	 * @return [type] [description]
	 */
	public function actlist()
	{
		$type       = I('get.type');
		$this->type = $type;
		$where      = array();
		switch ($type)
		{
			case '0':
				# code...
				break;
			case '1':
				$where['presellDateStart'] = array('gt',time()-24*60*60);
				break;
			case '2':
				$where['presellDateStart'] = array('elt',time()-24*60*60);
				$where['presellDateEnd'] = array('egt',time()-24*60*60);
				break;
			case '3':
				$where['paymentDateStart'] = array('elt',time()-24*60*60);
				$where['paymentDateEnd'] = array('egt',time()-24*60*60);
				break;
			case '4':
				$where['appointmentDateStart'] = array('elt',time()-24*60*60);
				$where['appointmentDateEnd'] = array('egt',time()-24*60*60);
				break;
			case '5':
				$where['appointmentDateEnd'] = array('lt',time()-24*60*60);
				break;
			default:
				# code...
				break;
		}
		$count     = M2('activity')->where($where)->count();
		$PageClass = new \Think\Page($count,10);
		$page      = $PageClass->show();
		$list      = M2('activity')->where($where)->limit($PageClass->firstRow.','.$PageClass->listRows)->order('id DESC')->select();

		foreach ($list as $key => $value)
		{
			if($value['presellDateStart']+24*60*60 > time())
			{
				$list[$key]['status'] = '待预售';
			}
			else if($value['presellDateStart']+24*60*60  <= time() && $value['presellDateEnd']+24*60*60 >= time())
			{
				$list[$key]['status'] = '预售中';
			}
			else if($value['paymentDateStart']+24*60*60  <= time() && $value['paymentDateEnd']+24*60*60 >= time())
			{
				$list[$key]['status'] = '支付尾款';
			}
			else if($value['appointmentDateStart']+24*60*60 <= time() && $value['appointmentDateEnd']+24*60*60 >= time())
			{
				$list[$key]['status'] = '预约中';
			}
			else
			{
				$list[$key]['status'] = '已结束';
			}
		}
		$this->page     = $page;
		$this->list     = $list;
		$this->menuID   = '87';
		$this->menuName = '活动管理列表';
		$this->display();
	}

	/**
	 * [actadd description]
	 * @return [type] [description]
	 */
	public function actadd()
	{
		if(IS_POST)
		{
			$data['title']                   = I('post.title');
			$data['presellDateStart']        = strtotime(I('post.presellDateStart'));
			$data['presellDateEnd']          = strtotime(I('post.presellDateEnd'));
			$data['presellDateFullPrice']    = I('post.presellDateFullPrice',0);
			$data['paymentDateStart']        = strtotime(I('post.paymentDateStart'));
			$data['paymentDateEnd']          = strtotime(I('post.paymentDateEnd'));
			$data['presellDatePaymentPrice'] = I('post.presellDatePaymentPrice',0);
			$data['appointmentDateStart']    = strtotime(I('post.appointmentDateStart'));
			$data['appointmentDateEnd']      = strtotime(I('post.appointmentDateEnd'));
			$data['actPic']                  = I('post.actPic');
			$result = M3('activity')->add($data);
			if($result != false)
			{
				$this->success('添加活动专题成功！',U(MODULE_NAME. '/Product/actlist'));
			}
			else
			{
				$this->error('添加活动专题失败！');
			}
			exit;
		}

		$this->menuID      = '87';
		$this->menuName    = '预售产品添加';
		$this->display();
	}
	/**
	 * [actedit description]
	 * @return [type] [description]
	 */
	public function actedit()
	{
		$id         = I('get.id');
		$this->id   = $id;
		$step       = I('get.step');
		$this->step = $step;
		if($id)
		{
			if(IS_POST)
			{
				switch ($step)
				{
					case '0':
						$data['title']                   = I('post.title');
						$data['presellDateStart']        = strtotime(I('post.presellDateStart'));
						$data['presellDateEnd']          = strtotime(I('post.presellDateEnd'));
						$data['presellDateFullPrice']    = I('post.presellDateFullPrice',0);
						$data['paymentDateStart']        = strtotime(I('post.paymentDateStart'));
						$data['paymentDateEnd']          = strtotime(I('post.paymentDateEnd'));
						$data['presellDatePaymentPrice'] = I('post.presellDatePaymentPrice',0);
						$data['appointmentDateStart']    = strtotime(I('post.appointmentDateStart'));
						$data['appointmentDateEnd']      = strtotime(I('post.appointmentDateEnd'));
						$data['actPic']                  = I('post.actPic');

						$result = M3('activity')->where(array('id'=>$id))->save($data);
						break;
					case '1':
						break;
					default:

						$data['title']                    = I('post.title');
						$data['presellDateStart']        = strtotime(I('post.presellDateStart'));
						$data['presellDateEnd']          = strtotime(I('post.presellDateEnd'));
						$data['presellDateFullPrice']    = I('post.presellDateFullPrice',0);
						$data['paymentDateStart']        = strtotime(I('post.paymentDateStart'));
						$data['paymentDateEnd']          = strtotime(I('post.paymentDateEnd'));
						$data['presellDatePaymentPrice'] = I('post.presellDatePaymentPrice',0);
						$data['appointmentDateStart']    = strtotime(I('post.appointmentDateStart'));
						$data['appointmentDateEnd']      = strtotime(I('post.appointmentDateEnd'));
						$data['actPic']                  = I('post.actPic');

						$result = M3('activity')->where(array('id'=>$id))->save($data);
						break;
				}

				if($result != false)
				{
					$this->success('修改成功！',U(MODULE_NAME. '/Product/actlist'));
				}
				else
				{
					$this->error('修改失败！');
				}
				exit;
			}

			$info             = M2('activity')->where(array('id'=>$id))->find();
			$this->info       = $info;
			$packageArr       = M2('activity_package')->where(array('activityID'=>$info['id']))->order('id')->select();
			foreach ($packageArr as $key => $value)
			{
				//套票中总分组数
				$packageArr[$key]['groupNums'] = M2('activity_package_group')->where(array('packageID'=>$value['id']))->order('id')->count();
				$groupArr                      = M2('activity_package_group')->where(array('packageID'=>$value['id']))->order('id')->select();
				foreach ($groupArr as $k => $v)
				{
					$productInfo[$key]['productArr'][$k] = M2('activity_package_group_product')->where(array('groupID'=>$v['id']))->select();
					//分组的产品数量
					$groupArr[$k]['productNums'] = count($productInfo[$key]['productArr'][$k]);
					//套票中计算总产品数
					foreach ($productInfo[$key]['productArr'] as $ki => $vi)
					{
						$packageArr[$key]['productNums'][$ki] = count($vi);
					}

					if($productInfo[$key]['productArr'][$k] == false)
					{
						$groupArr[$k]['productArr']['0'] = array('id'=>'', 'title' => '');
					}
					else
					{
						//产品标题、ID
						foreach ($productInfo[$key]['productArr'][$k] as $ki => $vi)
						{
							$groupArr[$k]['productArr'][$ki] = $productInfo[$key]['productArr'][$k][$ki];
							$groupArr[$k]['productArr'][$ki]['title'] = M2('pack_product_travel')->where(array('id'=>$vi['productID']))->getField('title');

						}
					}

				}

				//优惠券名称
				if($value['couponsID'] != false)
				{
					$listChild                       = M2('coupons_mould')->field('face_amount,cp_id')->where(array('id'=>$value['couponsID']))->find();
					$cooperative                     = M2('coupons_cooperation')->field('cooperative')->where(array('id'=>$listChild['cp_id']))->getField('cooperative');
					$packageArr[$key]['couponsName'] = $cooperative . '-【' . $listChild['face_amount']. '元】';
				}


				$packageArr[$key]['productNums'] = array_sum($packageArr[$key]['productNums']);
				$packageArr[$key]['groupArr']    = $groupArr;
			}
			$this->packageArr = $packageArr;
		}
		else
		{
			$this->redirect(MODULE_NAME. '/Product/actlist');
			exit;
		}

		$this->menuID      = '87';
		$this->menuName    = '预售产品编辑';
		$this->display();
	}

	/**
	 * [actdel description]
	 * @return [type] [description]
	 */
	public function actdel()
	{
		$id = I('get.id');
		if($id)
		{
			$result = M3('activity')->where(array('id'=>$id))->delete();
			if($result != false)
			{
				$this->success('删除成功！',U(MODULE_NAME. '/Product/actlist'));
			}
			else
			{
				$this->error('删除失败！');
			}
			exit;
		}
	}

	/**
	 * [presellDelAjax description]
	 * @return [type] [description]
	 */
	public function presellDelAjax()
	{
		$type   = I('post.type');
		$typeID = I('post.typeID');
		$pId    = I('post.pId');
		$title  = I('post.title');

		switch ($type)
		{
			case 'package':
				$result = M3('activity_package')->delete($typeID);
				break;
			case 'group':
				$result = M3('activity_package_group')->delete($typeID);
				break;
			case 'product':
				$result = M3('activity_package_group_product')->delete($typeID);
				break;
		}

		if($result == false)
		{
			$data['valid'] = false;
			$data['state'] = '删除'.$title.'失败！';
		}
		else
		{
			$data['valid'] = true;
			$data['state'] = '删除'.$title.'成功！';
		}

		$this->ajaxReturn($data);
	}
	/**
	 * [actDataAjax description]
	 * @return [type] [description]
	 */
	public function actDataAjax()
	{
		$type        = I('post.type');
		$typeID      = I('post.typeID');
		$executeType = I('post.executeType');
		$pId         = I('post.pId');
		switch ($type)
		{
			case 'package':
				$data['activityID']      = $pId;
				$data['title']           = I('post.title');
				$data['presellPrice']    = I('post.presellPrice');
				$data['paymentPrice']    = I('post.paymentPrice');
				$data['couponsID']       = I('post.couponsID');
				$data['appointmentNums'] = I('post.appointmentNums');
				switch ($executeType)
				{
					case 'add':
						$result = M3('activity_package')->add($data);
						break;
					case 'edit':
						$result = M3('activity_package')->where(array('id'=>$typeID))->save($data);
						break;
				}
				break;
			case 'group':
				$data['packageID']        = $pId;
				$data['title']            = I('post.title');
				$data['appointmentCheck'] = I('post.appointmentCheck',0);
				switch ($executeType)
				{
					case 'add':
						$result = M3('activity_package_group')->add($data);
						break;
					case 'edit':
						$result = M3('activity_package_group')->where(array('id'=>$typeID))->save($data);
						break;
				}
				break;
			case 'product':
				$data['groupID']          = $pId;
				$data['productID']          = I('post.productID');
				$data['appointmentCheck'] = I('post.appointmentCheck',0);
				switch ($executeType)
				{
					case 'add':
						$result = M3('activity_package_group_product')->add($data);
						break;
					case 'edit':
						$result = M3('activity_package_group_product')->where(array('id'=>$typeID))->save($data);
						break;
				}
				break;
		}

		if($result != false)
		{
			$data['valid'] = true;
			$data['state'] = '添加成功！';
		}
		else
		{
			$data['valid'] = false;
			$data['state'] = '添加失败！';
		}

		$this->ajaxReturn($data);
	}

	/**
	 * [productSearchAjax description]
	 * @return [type] [description]
	 */
	public function productSearchAjax()
	{
		$productID = I('post.productID');
		$title     = M2('pack_product_travel')->where(array('id'=>$productID))->getField('title');
		if($title == false)
		{
			$data['valid'] = false;
			$data['state'] = '没有查到你所查找的产品信息';
		}
		else
		{
			$data['valid'] = true;
			$data['title'] = $title;
		}

		$this->ajaxReturn($data);
	}
	/**
	 * [couponsListDataAjax description]
	 * 优惠券ajax请求列表
	 * @return [type] [description]
	 */
	public function couponsListDataAjax()
	{
		$title      = I('post.title');
		$returnData = array();
		$list       = M2('coupons_cooperation')->field('id,cooperative')->where(array('cooperative'=>array('LIKE',"%$title%")))->select();
		if($list == false)
		{
			$listChild = M2('coupons_mould')->field('id,face_amount,cp_id')->where(array('face_amount'=>array('LIKE',"%$title%")))->select();

			if($listChild == false)
			{
				$data['valid'] = false;
			}
			else
			{
				$data['valid'] = true;
				foreach ($listChild as $key => $value)
				{
					$list = M2('coupons_cooperation')->field('cooperative')->where(array('id'=>$value['cp_id']))->select();
					foreach ($list as $k => $v)
					{
						$returnData[$key][$k]['id'] = $value['id'];
						$returnData[$key][$k]['title'] = $v['cooperative'] . '-【' . $value['face_amount']. '元】';
					}
				}
			}
		}
		else
		{
			$data['valid'] = true;
			foreach ($list as $key => $value)
			{
				$listChild = M2('coupons_mould')->field('id,face_amount')->where(array('cp_id'=>$value['id']))->select();

				foreach ($listChild as $k => $v)
				{
					$returnData[$key][$k]['id'] = $v['id'];
					$returnData[$key][$k]['title'] = $value['cooperative'] . '-【' . $v['face_amount']. '元】';
				}
			}
		}

		$data['couponsData'] = $returnData;
		$this->ajaxReturn($data);
	}
	/**
	 * [visalist description]
	 * 签证产品列表
	 * @return [type] [description]
	 */
	public function visalist()
	{
		$countryID       = I('get.countryID');
		$schengen        = I('get.schengen');
		$this->countryID = $countryID;
		$this->schengen  = $schengen;

		$where           = array();
		if($schengen != false)
		{
			$where['schengenCheck'] = $schengen;
		}
		if($countryID != false)
		{
			$where['pid'] = $countryID;
		}
		else
		{
			$where['pid'] = array('neq','0');
		}
		$where['status']        = '1';
		$count                  = M2('visa_passport_type')->where($where)->count();
		$PageClass              = new \Think\Page($count,20);
		$page                   = $PageClass->show();

		$list = M2('visa_passport_type')->where($where)->limit($PageClass->firstRow.','.$PageClass->listRows)->order(array('status'=>'DESC','id'=>'DESC'))->select();
		foreach ($list as $key => $value)
		{
			$list[$key]['countryName'] = M2('visa_passport_type')->where(array('id'=>$value['pid']))->getField('name');
			switch ($value['validDateType'])
			{
				case 'D':
					$list[$key]['validDate'] = $value['validDate'] . '天';
					break;
				case 'M':
					$list[$key]['validDate'] = $value['validDate'] . '个月';
					break;
				case 'Y':
					$list[$key]['validDate'] = $value['validDate'] . '年';
					break;

				default:
					$list[$key]['validDate'] = '使馆批';
					break;
			}

			switch ($value['stopDateType'])
			{
				case 'D':
					$list[$key]['stopDate'] = $value['stopDate'] . '天';
					break;
				case 'M':
					$list[$key]['stopDate'] = $value['stopDate'] . '个月';
					break;
				case 'Y':
					$list[$key]['stopDate'] = $value['stopDate'] . '年';
					break;

				default:
					$list[$key]['stopDate'] = '使馆批';
					break;
			}

			switch ($value['entryNums'])
			{
				case '0':
					$list[$key]['entryNums'] = '使馆批';
					break;

				default:
					$list[$key]['entryNums'] = $value['entryNums'] . '次';
					break;
			}
		}
		$this->page     = $page;
		$this->list     = $list;

		$countryArr       = M2('visa_passport_type')->where(array('pid'=>'0'))->select();
		$this->countryArr = $countryArr;

		$this->menuID   = '76';
		$this->menuName = '签证产品列表';
		$this->display();
	}

	/**
	 * [visaadd description]
	 * 签证产品添加
	 * @return [type] [description]
	 */
	public function visaadd()
	{
		if(IS_POST)
		{
			$data['name']           = I('post.title');
			$data['pid']            = I('post.pid');
			$data['schengenCheck']  = I('post.schengenCheck');
			$coutryIDArr            = I('post.countryID',array());
			$data['countryID']      = implode('|',$coutryIDArr);
			$data['validDate']      = I('post.validDate');
			$data['validDateType']  = I('post.validDateType');
			$data['stopDate']       = I('post.stopDate');
			$data['stopDateType']   = I('post.stopDateType');
			$data['workDay']        = I('post.workDay');
			$data['entryNums']      = I('post.entryNums');
			$data['interviewCheck'] = I('post.interviewCheck');
			$data['costPrice']      = I('post.costPrice');
			$data['sellPrice']      = I('post.sellPrice');
			$provinceIDArr          = I('post.provinceID',array());
			$data['provinceID']     = implode('|',$provinceIDArr);
			$data['notice']         = I('post.notice');
			$data['remark']         = I('post.remark');
			$data['createTime']     = time();
			$data['status']         = '1';

			$visaProductID       = M3('visa_passport_type')->add($data);

			if($visaProductID != false)
			{
				$needData    = I('post.needData',array());
				$content     = I('post.content',array());
				$uploadPlugs = I('post.uploadPlugs',array());

				$count = count($needData);
				for ($i=0; $i < $count; $i++)
				{
					$addNeed['visaID']      = $visaProductID;
					$addNeed['title']       = $needData[$i];
					$addNeed['content']     = $content[$i];
					$addNeed['uploadPlugs'] = $uploadPlugs[$i];
					M3('visa_product_needdata')->add($addNeed);
				}

				$this->success('添加成功！',U(MODULE_NAME.'/Product/visalist'));
			}
			else
			{
				$this->error('添加失败！');
			}
			exit;
		}
		$countryArr = M2('visa_passport_type')->where(array('pid'=>'0'))->order('sort')->select();
		$countryHtml = '';
		$countryHtml .= '<select name="pid" style="margin-left: 5px;">';
		$countryHtml .= '<option value="0">请选择签证国家</option>';
		foreach ($countryArr as $key => $value)
		{
			$countryHtml .= '<option value="'.$value['id'].'">'.$value['name'].'</option>';
		}
		$countryHtml .= '</select>';
		$this->countryHtml = $countryHtml;
		$this->destinationHtml = destinationHtml('', 'areaID', '1', 'destinationSelect(this)');
		$this->provinceHtml    = provinceHtml();
		$this->menuID          = '76';
		$this->menuName        = '签证产品添加';
		$this->display();
	}

	/**
	 * [visaedit description]
	 * 签证产品编辑
	 * @return [type] [description]
	 */
	public function visaedit()
	{
		$id = I('get.id');
		$this->id = $id;
		if(IS_POST)
		{
			$data['pid']            = I('post.pid');
			$data['name']           = I('post.title');
			$data['schengenCheck']  = I('post.schengenCheck');
			$coutryIDArr            = I('post.countryID',array());
			$data['countryID']      = implode('|',$coutryIDArr);
			$data['validDate']      = I('post.validDate');
			$data['validDateType']  = I('post.validDateType');
			$data['stopDate']       = I('post.stopDate');
			$data['stopDateType']   = I('post.stopDateType');
			$data['workDay']        = I('post.workDay');
			$data['entryNums']      = I('post.entryNums');
			$data['interviewCheck'] = I('post.interviewCheck');
			$data['costPrice']      = I('post.costPrice');
			$data['sellPrice']      = I('post.sellPrice');
			$provinceIDArr          = I('post.provinceID',array());
			$data['provinceID']     = implode('|',$provinceIDArr);
			$data['notice']         = I('post.notice');
			$data['remark']         = I('post.remark');
			$data['status']         = '1';

			$result = M3('visa_passport_type')->where(array('id'=>$id))->save($data);

			if($result != false)
			{
				$needDataID  = I('post.needDataID',array());
				$needData    = I('post.needData',array());
				$content     = I('post.content',array());
				$uploadPlugs = I('post.uploadPlugs',array());

				$count = count($needData);
				for ($i=0; $i < $count; $i++)
				{
					$addNeed['title']       = $needData[$i];
					$addNeed['content']     = $content[$i];
					$addNeed['uploadPlugs'] = $uploadPlugs[$i];
					if($needDataID[$i] == false)
					{
						$addNeed['visaID'] = $id;
						M3('visa_product_needdata')->add($addNeed);
					}
					else
					{
						M3('visa_product_needdata')->where(array('id'=>$needDataID[$i]))->save($addNeed);
					}
				}

				$this->success('修改成功！',U(MODULE_NAME.'/Product/visalist'));
			}
			else
			{
				$this->error('修改失败！');
			}
			exit;

		}

		$visaProduct       = M2('visa_passport_type')->where(array('id'=>$id))->find();

		$countryIDs        = str_replace("|", ",", $visaProduct['countryID']);
		$countryArr        = M2('destination')->field('id,name')->where(array('id'=>array('IN',$countryIDs)))->select();
		$this->countryArr  = $countryArr;

		$provinceIDs       = str_replace("|", ",", $visaProduct['provinceID']);
		$provinceArr       = M2('address_province')->where(array('province_id'=>array('IN',$provinceIDs)))->select();
		$this->provinceArr = $provinceArr;

		$this->visaProduct = $visaProduct;

		$needDataArr       = M2('visa_product_needdata')->where(array('visaID'=>$id))->select();
		$this->needDataArr = $needDataArr;

		$this->destinationHtml = destinationHtml('', 'areaID', '1', 'destinationSelect(this)');

		$visaCountryArr = M2('visa_passport_type')->where(array('pid'=>'0'))->order('sort')->select();
		$countryHtml = '';
		$countryHtml .= '<select name="pid" style="margin-left: 5px;">';
		$countryHtml .= '<option value="0">请选择签证国家</option>';
		foreach ($visaCountryArr as $key => $value)
		{
			if($value['id'] == $visaProduct['pid'])
			{
				$countryHtml .= '<option value="'.$value['id'].'" selected>'.$value['name'].'</option>';
			}
			else
			{
				$countryHtml .= '<option value="'.$value['id'].'">'.$value['name'].'</option>';
			}
		}
		$countryHtml .= '</select>';
		$this->countryHtml = $countryHtml;

		$this->provinceHtml    = provinceHtml();

		$this->menuID          = '76';
		$this->menuName        = '签证产品编辑';
		$this->display();
	}

	/**
	 * [visadel description]
	 * 签证产品删除
	 * @return [type] [description]
	 */
	public function visadel()
	{
		$id             = I('get.id');
		$data['status'] = '0';
		$result         = M3('visa_product')->where(array('id'=>$id))->save($data);

		if($result != false)
		{
			$this->success('删除成功！');
		}
		else
		{
			$this->error('删除失败！');
		}
		exit;
	}
	/**
	 * [delNeedDataAjax description]
	 * @return [type] [description]
	 */
	public function delNeedDataAjax()
	{
		$id = I('post.id');
		if($id)
		{
			$result = M3('visa_product_needdata')->where(array('id'=>$id))->delete();
		}

		if($result != false)
		{
			$data['valid'] = true;
			$data['state'] = '删除成功';
		}
		else
		{
			$data['valid'] = false;
			$data['state'] = '删除失败';
		}
		$this->ajaxReturn($data);
	}
	/**
	 * [addVisaCountryAjax description]
	 *
	 */
	public function addVisaCountryAjax()
	{
		$countryName = I('post.countryName');
		if($countryName != false)
		{
			$data['name'] = $countryName;
			$data['pid']  = '0';
			$result = M3('visa_passport_type')->add($data);
			if($result != false)
			{
				$data['valid'] = true;
				$data['state'] = '添加成功';
			}
			else
			{
				$data['valid'] = false;
				$data['state'] = '添加失败';
			}
		}
		else
		{
			$data['valid'] = false;
			$data['state'] = '签证国家不能为空';
		}
		$this->ajaxReturn($data);
	}

	/**
	 * [addInsuranceList description]
	 * 单品库列表
	 * @return [type] [description]
	 */
	public function singleList()
	{

		$type             = I('post.type',0);
		$this->type       = $type;
		$keyword          = I('post.keyword','');
		$this->keyword    = $keyword;
		$where            = array();
		if($type != 0)$where['type'] = $type;
		if($keyword)$where['_string'] = '`title` LIKE "%'.$keyword.'%" OR `id`="'.$id.'"';

		$count = M2('pack_contains')->where($where)->count();
		$PageClass  = new \Think\Page($count,10);
		$page  = $PageClass->show();

		$list = M2('pack_contains')->where($where)->limit($PageClass->firstRow.','.$PageClass->listRows)->order(array('id'=>'DESC'))->select();

		foreach ($list as $key => $value)
		{
			switch ($value['type'])
			{
				case '1':
					$typeName = '附加保险';
					break;
				case '2':
					$typeName = '附加产品';
					break;
				case '3':
					$typeName = '包含单品';
					break;
				case '4':
					$typeName = '赠送单品';
					break;
			}
			$list[$key]['typeName'] = $typeName;
		}
		$this->page     = $page;
		$this->list    	= $list;

		$this->menuID   = '131';
		$this->menuName = '单品库列表';
		$this->display();
	}

	/**
	 * [addInsuranceedit description]
	 * 单品库编辑
	 * @return [type] [description]
	 */
	public function singleEdit()
	{
		$id = I('get.id');
		$this->id = $id;
		if(IS_POST)
		{
			if($id)
			{
				$data['type']      = I('post.type');
				$data['title']     = I('post.title');
				$data['price']     = I('post.price');
				$data['uploadImg'] = I('post.uploadImg');
				$result = M3('pack_contains')->where(array('id'=>$id))->save($data);
			}
			else
			{
				$data['type']       = I('post.type');
				$data['title']      = I('post.title');
				$data['price']      = I('post.price');
				$data['uploadImg']  = I('post.uploadImg');
				$data['createTime'] = time();
				$result = M3('pack_contains')->add($data);
			}

			if($result != false)
			{
				$this->redirect(MODULE_NAME.'/Product/singleList');
			}
			else
			{
				$this->error('编辑失败！');
			}
			exit;
		}

		if($id)
		{
			$info = M2('pack_contains')->where(array('id'=>$id))->find();
			$this->info = $info;
		}
		$this->menuID   = '131';
		$this->menuName = '单品库编辑';
		$this->display();
	}


}

/**
 * [departureHtml description]
 * @param  [type]  $departureCityIDStr [description]
 * @param  boolean $name               [description]
 * @return [type]                      [description]
 */
function departureHtml($departureCityIDStr,$name = false)
{
	$departureCityIDArr     = explode('|', $departureCityIDStr);
	$departureCityIDArrNums = count($departureCityIDArr);
	$departureCityArr       = M2('departure')->field('id,name')->order('sort')->select();
	$departureHtml          = array();
	$name = isset($name) ? $name : 'departureCityID[]';

	for ($i=0; $i < $departureCityIDArrNums; $i++)
	{
		$departureHtml[$i] = '';
		$departureHtml[$i] .= '<select name="'.$name.'">';
		$departureHtml[$i] .= '<option value="0">请选择城市</option>';
		foreach ($departureCityArr as $key => $value)
		{
			if($departureCityIDArr[$i] == $value['id'])
			{
				$departureHtml[$i] .= '<option value="'.$value['id'].'" selected >'.$value['name'].'</option>';
			}
			else
			{
				$departureHtml[$i] .= '<option value="'.$value['id'].'">'.$value['name'].'</option>';
			}
		}
		$departureHtml[$i] .= '</select>';
	}

	return $departureHtml;
}
/**
 * [destinationHtml description]
 * @return [type] [description]
 */
function destinationHtml($destinationID, $name = false, $deep = '1', $function = false)
{
	$destinationPID = M2('destination')->where(array('id'=>$destinationID))->getField('pid');
	$destinationPID = isset($destinationPID) ? $destinationPID : '0';
	$destinationArr = M2('destination')->where(array('pid'=>$destinationPID))->order('sort')->select();
	switch ($deep)
	{
		case '1':
			$htmlName = '大洲';
			$name = isset($name) ? $name : 'areaID[]';
			break;
		case '2':
			$htmlName = '国家';
			$name = isset($name) ? $name : 'countryID[]';
			break;
		case '3':
			$htmlName = '城市';
			$name = isset($name) ? $name : 'cityID[]';
			break;
		default:
			$htmlName = '大洲';
			$name = isset($name) ? $name : 'areaID[]';
			break;

	}

	$destinationHtml = '';
	$destinationHtml .= '<select name="'.$name.'" onChange="'.$function.'" >';
	$destinationHtml .= '<option value="0">请选择'.$htmlName.'</option>';
	foreach ($destinationArr as $key => $value)
	{
		if($destinationID == $value['id'])
		{
			$destinationHtml .= '<option value="'.$value['id'].'" selected >'.$value['name'].'</option>';
		}
		else
		{
			$destinationHtml .= '<option value="'.$value['id'].'">'.$value['name'].'</option>';
		}
	}
	$destinationHtml .= '</select>';

	return $destinationHtml;
}

/**
 * [destinationChildHtml description]
 * @return [type] [description]
 */
function destinationChildHtml($destinationID)
{
	$destinationArr = M2('destination')->where(array('pid'=>$destinationID))->select();

	$destinationHtmlOption = '';
	foreach ($destinationArr as $key => $value)
	{
		$destinationHtmlOption .= '<option value="'.$value['id'].'">'.$value['name'].'</option>';
	}

	return $destinationHtmlOption;
}
/**
 * [provinceHtml description]
 * @return [type] [description]
 */
function provinceHtml()
{
	$provinceArr = M2('address_province')->order('province_id')->select();
	$provinceHtml = '';
	$provinceHtml .= '<select name="provinceID" >';
	$provinceHtml .= '<option value="0">请选择省份</option>';
	foreach ($provinceArr as $key => $value)
	{
		$provinceHtml .= '<option value="'.$value['province_id'].'">'.trim($value['province_name']).'</option>';
	}
	$provinceHtml .= '</select>';

	return $provinceHtml;
}


function originalImagesMobile($originalImages)
{
	$pathArr = explode('/',$originalImages);
	$imgname = end($pathArr);

	$originalImagesMobile = str_replace($imgname,'mobile_'.$imgname,$originalImages);

	if( !@fopen( $originalImagesMobile , 'r' ) )
    {
    	$arr = explode('.',$imgname);

        $dataPost = array(
    		'ext'=>$arr[1],
    		'saveName'=>$imgname,
    		'savePath'=>str_replace('http://www.tripvip.cn/Upload/','',str_replace($imgname,'',$originalImages)),
    		'randNums'=>substr($arr[0],0,6)
		);

    	$ch = curl_init ();
		curl_setopt ( $ch, CURLOPT_URL, 'http://www.tripvip.cn/center/public/cropBigPic' );
		curl_setopt ( $ch, CURLOPT_POST, 1 );
		curl_setopt ( $ch, CURLOPT_HEADER, 0 );
		curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
		curl_setopt ( $ch, CURLOPT_POSTFIELDS, $dataPost );
		$originalImagesMobile = curl_exec ( $ch );
		curl_close ( $ch );
    }

    return 'http://www.tripvip.cn'.$originalImagesMobile;
}

function imgUrlComplete($url)
{

	if(strstr($url,'http://www.tripvip.cn') == false && empty($url) == false)
	{
		return 'http://www.tripvip.cn'.$url;
	}
	else
	{
		return $url;
	}
}


function delImg($str)
{
	if(empty($str) == false)
	{
		$wenUrl = imgUrlComplete($str);

		if( @fopen( $wenUrl , 'r' ) )
		{
			$Ftp = new \Think\Ftp();
			$Ftp->del_currFile(str_replace('http://www.tripvip.cn','',$wenUrl));
		}
	}

	return true;
}
?>